fork download
  1. A = [[12606.0, 74204.0, 56.0, 64.0, 72.0, 21.6, 18.0, 0.0, 0.0],
  2. [12606.0, 105492.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 45.6],
  3. [12606.0, 112151.0, 2.4, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0],
  4. [12606.0, 121896.0, 0.0, 0.0, 0.0, 0.0, 0.0, 60.8, 0.0],
  5. [12901.0, 74204.0, 25.0, 15.0, 45.0, 38.6, 18.0, 0.0, 0.0],
  6. [12901.0, 105492.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 45.6]]
  7.  
  8. from collections import defaultdict
  9. d = defaultdict(list)
  10. for row in A:
  11. d[row[0]].append(row[2:]) # append all rows with same ID number.
  12.  
  13. print {k:[sum(col) for col in zip(*rows)] for k, rows in d.items()}
Success #stdin #stdout 0.01s 7864KB
stdin
Standard input is empty
stdout
{12901.0: [25.0, 15.0, 45.0, 38.6, 18.0, 0.0, 45.6], 12606.0: [58.4, 68.0, 72.0, 21.6, 18.0, 60.8, 45.6]}