Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created July 10, 2020 03:02
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/9a851fcd3f26530d635efb02365726b2 to your computer and use it in GitHub Desktop.
Save IndhumathyChelliah/9a851fcd3f26530d635efb02365726b2 to your computer and use it in GitHub Desktop.
from collections import Counter
c=Counter({'a':1,'b':3,'c':5,'d':5})
print (c)#Output:Counter({'c': 5, 'd': 5, 'b': 3, 'a': 1})
#getting count of element 'a'
print (c['a'])#Output:1
#getting count of missing elements return 0.
print (c['z'])#Output:0
#deleting elements from the Counter object
del c['b']
print (c)#Output:Counter({'c': 5, 'd': 5, 'a': 1})
#setting count to 0, doesn't remove elements from the Counter object
c['a']=0
print (c)#Output:Counter({'c': 5, 'd': 5, 'a': 0})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment