I have a list of lists named allBins
which contains several lists which represent different bins, inside those bins are varying numbers of tuples with the format (iD, volume). I need to iterate through to sum the volumes of the items in each of the bins by summing the second element of the tuples.
I've tried many things:
sum(bin[1] for bin in allBins)
gives me a 'list index out of range' error presumably because some bins have more than one tuple?
allBins = [[(3,20)],[(1,11),(0,6)],[(4,16),(2,5)]]
I need a line of code that, depending on which bin I choose to sum, gives me the following integers:
1st bin: 20
2nd bin: 17
3rd bin: 21