Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created July 10, 2020 05:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IndhumathyChelliah/33d0fd57fa501d4c353952f4e2f4d281 to your computer and use it in GitHub Desktop.
Save IndhumathyChelliah/33d0fd57fa501d4c353952f4e2f4d281 to your computer and use it in GitHub Desktop.
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