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 151 views
1 answer 175 views
1 answer 182 views
182 views asked Sep 15, 2018 by avibootz
2 answers 238 views
1 answer 159 views
1 answer 543 views
...