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})
#Intersection:min(c1,c2)
c3=c1&c2
#negative values and zero are ignored
print (c3)#Output:Counter({'a': 1})
c4=Counter({'a':1,'b':2,'c':-5})
c5=Counter({'a':2,'c':2,'e':4})
#Union:max(c4,c5)
c6=c4|c5
print (c6)#Output:Counter({'e': 4, 'a': 2, 'b': 2, 'c': 2})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment