Retired

Thinkful - Dictionary Drills: Multiple Modes (retired)

1,016 of 1,017Grae-Drake

Description:

You probably know that the "mode" of a set of data is the data point that appears most frequently. Looking at the characters that make up the string "sarsaparilla" we can see that the letter "a" appears four times, more than any other letter, so the mode of "sarsaparilla" is "a".

But do you know what happens when two or more data points occur the most? For example, what is the mode of the letters in "tomato"? Both "t" and "o" seem to be tied for appearing most frequently.

Turns out that a set of data can, in fact, have multiple modes, so "tomato" has two modes: "t" and "o". It's important to note, though, that if all data appears the same number of times there is no mode. So "cat", "redder", and [1, 2, 3, 4, 5] do not have a mode.

Your job is to write a function modes() that will accept one argument data that is a sequence like a string or a list of numbers and return a sorted list containing the mode(s) of the input sequence. If data does not contain a mode you should return an empty list.

For example:

>>> modes("tomato")
["o", "t"]
>>> modes([1, 3, 3, 7])
[3]
>>> modes(["redder"])
[]

You can trust that your input data will always be a sequence and will always contain orderable types (no inputs like [1, 2, 2, "a", "b", "b"]).

Fundamentals
Lists

Stats:

CreatedJan 6, 2017
Warriors Trained1542
Total Skips20
Total Code Submissions7217
Total Times Completed1017
Python Completions1016
Total Stars32
% of votes with a positive feedback rating90% of 157
Total "Very Satisfied" Votes131
Total "Somewhat Satisfied" Votes22
Total "Not Satisfied" Votes4
Total Rank Assessments12
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • Grae-Drake Avatar
  • user5036852 Avatar
Ad