2 ms·
It's `reduce(add, map(int, ...))`. It's more general than `sum(generator)` - you could write `reduce(mul, ...)` or anything else, while with sum you'll get sum
by klibertp 13y ago
It's `reduce(add, map(int, ...))`.
It's more general than `sum(generator)` - you could write `reduce(mul, ...)` or anything else, while with sum you'll get sum and nothing more. Also, I have no problem with `reduce(some_fun, (x for x in iterable))`, which works too.
Generally, while `map` in python is much better written as list comprehension or generator expression, reduce has no equivalent short of explicit loop with accumulator variable.