Answers for "print the most recurring element in a list"

3

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)) # the one most common element... 2 would mean the 2 most common
[(9216, 2)] # a set containing the element, and it's count in 'a'
Posted by: Guest on July-07-2020
0

get most recurring element in a list python

from collections import Counter
# Given list
listA = [45, 20, 11, 50, 17, 45, 50,13, 45]
print("Given List:n",listA)
occurence_count = Counter(listA)
res=occurence_count.most_common(1)[0][0]
print("Element with highest frequency:n",res)
Posted by: Guest on June-06-2021

Code answers related to "print the most recurring element in a list"

Python Answers by Framework

Browse Popular Code Answers by Language