Example 1: most frequent word in a list python
words = [
'red', 'green', 'black', 'pink', 'black', 'white', 'black', 'eyes',
'white', 'black', 'orange', 'pink', 'pink', 'red', 'red', 'white', 'orange',
'white', "black", 'pink', 'green', 'green', 'pink', 'green', 'pink',
'white', 'orange', "orange", 'red'
]
from collections import Counter
word_counts = Counter(words)
top_four = word_counts.most_common(4)
print(top_four)
Example 2: python find most occuring element
from collections import Counter
a = [1936, 2401, 2916, 4761, 9216, 9216, 9604, 9801]
c = Counter(a)
print(c.most_common(1))
[(9216, 2)]
Example 3: how to get the most common number in python
>>> from statistics import mode
>>> mode((1, 2, 4, 4, 5, 4, 4, 2, 3, 8, 4, 4, 4))
4