Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created July 10, 2020 05:07
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/65184ccada9114159dfe043793c61a10 to your computer and use it in GitHub Desktop.
Save IndhumathyChelliah/65184ccada9114159dfe043793c61a10 to your computer and use it in GitHub Desktop.
c=Counter({'a':1,'b':2,'c':-5})
#list unique elements
print (list(c))#Output:['a', 'b', 'c']
#converts to set containing elements
print (set(c))#Output:{'c', 'a', 'b'}
#converts to a regular dictionary
print (dict(c))#Output:{'a': 1, 'b': 2, 'c': -5}
#convert to list of tuple.
print (c.items())#Output:dict_items([('a', 1), ('b', 2), ('c', -5)])
#Converting form list of tuples
c1=Counter([('a',1),('b',2)])
print (c1)#Output:Counter({('a', 1): 1, ('b', 2): 1})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment