How to union two counter objects in Python

1 Answer

0 votes
from collections import Counter
 
c = Counter(a=2, b=0, c=9, d=-3, f=7)
d = Counter(a=1, b=2, c=3, e=4, g=8)

cd = c | d
 
print(cd)
 
 
'''
run:
  
Counter({'c': 9, 'g': 8, 'f': 7, 'e': 4, 'b': 2, 'a': 2})
 
'''

 



answered Nov 7, 2018 by avibootz

Related questions

1 answer 238 views
1 answer 271 views
1 answer 275 views
275 views asked Sep 15, 2018 by avibootz
2 answers 373 views
1 answer 260 views
1 answer 671 views
...