Skip to content

Instantly share code, notes, and snippets.

Created July 10, 2020 03:02
What would you like to do?
from collections import Counter
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
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