Advertisement
Guest User

Untitled

a guest
Dec 27th, 2013
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. d1 = {'a':1, 'b':3}
  2. d2 = {'a':5, 'd':5}
  3. d3 = {'c':2, 'f':1}
  4.  
  5. d = {'a':5, 'b':3, 'c':2, 'd':5, 'f':1}
  6.  
  7. >>> from collections import Counter
  8. >>> d1 = {'a':1, 'b':3}
  9. >>> d2 = {'a':5, 'd':5}
  10. >>> d3 = {'c':2, 'f':1}
  11. >>> Counter(d1) | Counter(d2) | Counter(d3)
  12. Counter({'a': 5, 'd': 5, 'b': 3, 'c': 2, 'f': 1})
  13.  
  14. >>> from collections import Counter, OrderedDict
  15. >>> OrderedDict(sorted((Counter(d1) | Counter(d2) | Counter(d3)).items()))
  16. OrderedDict([('a', 5), ('b', 3), ('c', 2), ('d', 5), ('f', 1)])
  17.  
  18. >>> from functools import reduce
  19. >>> from operator import or_
  20. >>> reduce(or_, map(Counter, (d1, d2, d3)))
  21. Counter({'a': 5, 'd': 5, 'b': 3, 'c': 2, 'f': 1})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement