-
-
Save IndhumathyChelliah/33d0fd57fa501d4c353952f4e2f4d281 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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