I have a list of tuples of lists... :
lst = [(['a', 1], ['b', 2]), (['c', 3], ['d', 4], ['e', 5])]
And I want to get the sum of index[1] of every lists in each tuples (first tuple = 3, second tuple = 12) result can look like this:
['ab', 3]
['cde', 12]
I tried this :
for tuples in lst:
total = [x + y for (x, y) in zip(*tuples)]
print(total)
but if a tuple has more than 2 values (like the second one) I will get a value error.
I need to get the sum of every lists no matter the number of lists in each tuples
So I tried this instead:
for tuples in lst:
sum = [sum(x) for x in zip(*tuples)]
But I get a TypeError: 'list' object is not callable
Any ideas ?
sumas variable name caused your error. I replaced the otherslist/sumbut left this one for reproducibility of the errorprintshould really never be used for its property to yield elements. Use a generator, or collect in a list.[x for x in lst if sum(list(zip(*x))[1])<=500]