Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. lista = [['Day', 'Cost', 'Clicks'], ['2019-03-21', 50300.0, 39], ['2019-03-21', 49270.0, 307], ['2019-03-21', 23630.0, 15], ['2019-03-21', 150110.0, 525], ['2019-03-21', 12120.0, 33], ['2019-03-21', 605330.0, 4033], ['2019-03-21', 1040490.0
  2. , 4435], ['2019-03-21', 191390.0, 758], ['2019-03-21', 42230.0, 155], ['2019-03-21', 305110.0, 760], ['2019-03-22', 164150.0, 642], ['2019-03-22', 3717300.0, 17370], ['2019-03-23', 39130.0, 65], ['2019-03-23', 3717300.0, 17370], ['2019-03-24', 39130.0, 65]]
  3.  
  4.  
  5. def sumByDate(list):
  6.     newList = [[list[0][0], list[0][1], list[0][2]], [list[1][0], 0, 0]]
  7.     j = 1
  8.     for i in range(1, len(list)):
  9.  
  10.         if (newList[j][0] == list[i][0]):
  11.             newList[j] = [newList[j][0], newList[j][1] + list[i][1], newList[j][2] + list[i][2]]
  12.         else:
  13.             newList.append([list[i][0], list[i][1], list[i][2]])
  14.             j += 1
  15.     return(newList)
  16.  
  17. print(sumByDate(lista))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement