I have a list of tuples (always pairs) like this:
[(0, 1), (2, 3), (5, 7), (2, 1)]
I\'d like to find the sum of the first items in each pai
sum(i for i, j in list_of_pairs)
will do too.
I recommend:
sum(i for i, _ in list_of_pairs)
Note:
Using the variable _
(or __
to avoid confliction with the alias of gettext
) instead of j
has at least two benefits:
_
(which stands for placeholder) has better readabilitypylint
won't complain: "Unused variable 'j'"