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':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