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':2,'b':1,'c':4,'d':3}) | |
print (c)#Output:Counter({'c': 4, 'd': 3, 'a': 2, 'b': 1}) | |
elem=c.elements() | |
#returns an iterator | |
print (elem)#Output:<itertools.chain object at 0x0240EC10> | |
#converting iterator to list object | |
print (list(elem))#Output:['a', 'a', 'b', 'c', 'c', 'c', 'c', 'd', 'd', 'd'] | |
c1=Counter({'a':0,'b':2}) | |
#Elements with count less than one are ignored. | |
print (list(c1.elements()))#Output:['b', 'b'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment