30 seconds of python

  Back to Home

most_frequent

listbeginner

Returns the most frequent element in a list.

Use set(list) to get the unique values in the list combined with max() to find the element that has the most appearances.

def most_frequent(list):
  return max(set(list), key = list.count)