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 164 views
1 answer 184 views
1 answer 190 views
190 views asked Sep 15, 2018 by avibootz
2 answers 256 views
1 answer 174 views
1 answer 557 views
...