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