416 B
416 B
title, type, tags, cover, dateModified
| title | type | tags | cover | dateModified | |
|---|---|---|---|---|---|
| Most frequent element | snippet |
|
secret-tree | 2020-11-02T19:28:27+02:00 |
Returns the most frequent element in a list.
- Use
set()to get the unique values inlst. - Use
max()to find the element that has the most appearances.
def most_frequent(lst):
return max(set(lst), key = lst.count)
most_frequent([1, 2, 1, 2, 3, 2, 1, 4, 2]) #2