Find the most common element in a list
Most common element in a list
from collections import Counter thelist = [1, 4, 2, 3, 5, 4, 5, 6, 7, 8, 1, 3, 4, 5, 9, 10, 11] c = Counter(thelist) print(c.most_common(1))
[(4, 3)]
from collections import Counter thelist = [1, 4, 2, 3, 5, 4, 5, 6, 7, 8, 1, 3, 4, 5, 9, 10, 11] c = Counter(thelist) print(c.most_common(1))
[(4, 3)]