Editor settings

General settings

Save settings

Learn to program with Python

Find the mode from a list #

Write a function that takes a list and returns the mode, which is the value that appears most frequently in the list. If there are multiple modes, return a list of all the modes.


Tests #

  • find_the_mode([1, "apple", "apple", "banana", 1, None, "apple"]) should return ["apple"]
  • find_the_mode([1, 2, 3, "apple", "banana", 2, "banana", None]) should return [2, 'banana']
  • find_the_mode(["apple", "orange", "apple", "banana", None, None, "banana", "orange", "apple"]) should return ["apple"]
  • find_the_mode([None, None, None, None, None]) should return [None]
  • find_the_mode([1, "1", 2, "2", 3, "3"]) should return [1, '1', 2, '2', 3, '3']
Output will be displayed here