Files
30-seconds-of-code/snippets/most_frequent.md
2019-10-11 23:40:49 +02:00

363 B

title, tags
title tags
most_frequent array,beginner

Method return the most frequent element that appears in a list.

Upon calling the function, in return you a value, which most frequently appears in the list.

def most_frequent(list):
    return max(set(list), key = list.count)
numbers = [1,2,1,2,3,2,1,4,2]
most_frequent(numbers) #2