Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created Jul 10, 2020
Embed
What would you like to do?
from collections import Counter
c1=Counter({'a':1,'b':2,'c':-5})
c2=Counter({'a':2,'c':2,'e':4})
#Addition operations- add count of corresponding elements
c3=c1+c2
#negative values are ignored.
print (c3)#Output:Counter({'e': 4, 'a': 3, 'b': 2})
c4=Counter({'a':1,'b':2,'c':-5})
c5=Counter({'a':2,'c':2,'e':4})
#subtraction operation- subtract count of corresponding elements
c6=c4-c5
print (c6)#Output:Counter({'b': 2})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment