I have a 2D list in python. I'd like to return the value of the first dimension where the sum of the second value is maximized. I don't care about breaking any ties and my first dimension will always be 1 through 6.
For example:
1)
list=[(1,200),(1,50),(2,275)]
should return 2 since 275 > 250
2)
list= [(1,100),(2,50),(2,300),(1,1000)
should return 1 since 1100 > 350
My attempted solution would work but be suboptimal (ideally id like a short 1-3 line solution) and uses the fact that my first dimension will only be the values 1-6. I'd like something a bit cleaner.
#for each element 1 through 6
For i in range(len(list)):
if list[i][0]=1:
#do this for oneSum, twoSum, etc, and take the largest sum
oneSum+=list[i][1]