How do I sum the first value in a set of lists within a tuple?
问题 Hey, I would like to be able to perform this but with being selective for which lists I sum up. Let's say, that same example, but with only adding up the first number from the 3rd and 4th list. 回答1: Something like: sum(int(tuple_list[i][0]) for i in range(3,5)) range(x, y) generates a list of integers from x(included) to y(excluded) and 1 as the step. If you want to change the range(x, y, step) will do the same but increasing by step. You can find the official documentation here Or you can do