fork download
  1. list1 = [2, 3, 3, 4, 4, 5]
  2. list2 = [-4, 8, -4, 8, -1, 2]
  3.  
  4. from collections import defaultdict
  5.  
  6. d = defaultdict(int)
  7. for k, v in zip(list1, list2):
  8. d[k] += v
  9.  
  10. print d
Success #stdin #stdout 0.01s 6412KB
stdin
Standard input is empty
stdout
defaultdict(<type 'int'>, {2: -4, 3: 4, 4: 7, 5: 2})