set()
to get the unique values in lst
.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
Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️