Q:

Write a Python program to find the most common element of a given list.

0

Write a Python program to find the most common element of a given list. 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

from collections import Counter
language = ['PHP', 'PHP', 'Python', 'PHP', 'Python', 'JS', 'Python', 'Python','PHP', 'Python']
print("Original list:")
print(language)
cnt = Counter(language)
print("\nMost common element of the said list:")
print(cnt.most_common(1)[0][0])

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now