I have an iterable delta that generates tuple of two numbers (dx, dy), and I want to compute the sum of each. The following doesn't work since delta is disposed after the first iteration.
x = sum(dx for dx, dy in delta)
y = sum(dy for dx, dy in delta)
Any idea? I'm thinking in the direction of somehow turning delta into two iterables of dx and dy, but have reached nothing so far.
Use zip() and map() functions to apply the sum() on each column:
x, y = map(sum, zip(*delta))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With