I have structure like this:
structure = [('a', 1), ('b', 3), ('c', 2)]
I would like to sum the integers (1+3+2) using sum() builtin method (in one line).
Any ideas?
I have structure like this:
structure = [('a', 1), ('b', 3), ('c', 2)]
I would like to sum the integers (1+3+2) using sum() builtin method (in one line).
Any ideas?
sum(n for _, n in structure)
would work.
Using a functional style, you could do
reduce(lambda x,y:x+y[1], structure,0)