Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created July 10, 2020 03:55
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/adae8851a277b082841c9565e01cbb83 to your computer and use it in GitHub Desktop.
Save IndhumathyChelliah/adae8851a277b082841c9565e01cbb83 to your computer and use it in GitHub Desktop.
from collections import Counter
c1=Counter({'a':2,'b':1,'c':4,'d':3})
c2=Counter({'a':3,'b':5,'e':7})
#subtracts the count of respective elements
c1.subtract(c2)
#both input and output may be zero or negative.
print (c1)#Output:Counter({'c': 4, 'd': 3, 'a': -1, 'b': -4, 'e': -7})
#dict update
#Update() method adds elements to the dictionary if key is not in that dictionary. If key is in the dictionary means, it will update the new value.
d1={'a':2,'b':1,'c':4,'d':3}
d2={'a':3,'b':5,'e':7}
d1.update(d2)
print (d1)#Output:{'a': 3, 'b': 5, 'c': 4, 'd': 3, 'e': 7}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment