Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created Jul 10, 2020
Embed
What would you like to do?
from collections import Counter
c=Counter({'a':1,'b':2,'c':-5,'d':3})
#It will return list of elements from most common to least common
l=c.most_common()
print (l)#Output:[('d', 3), ('b', 2), ('a', 1), ('c', -5)]
#Most common element can be found by accessing first index l[0]
print (l[0])#Output:('d', 3)
#Least common element can be found by accessing last index l[-1]
print (l[-1])#Output:('c', -5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment