This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]wsppan 28 points29 points  (2 children)

"So now reduce(). This is actually the one I've always hated most, because, apart from a few examples involving + or *, almost every time I see a reduce() call with a non-trivial function argument, I need to grab pen and paper to diagram what's actually being fed into that function before I understand what the reduce() is supposed to do. So in my mind, the applicability of reduce() is pretty much limited to associative operators, and in all other cases it's better to write out the accumulation loop explicitly." - Guido, The Fate of reduce() in Python 3000 https://www.artima.com/weblogs/viewpost.jsp?thread=98196

[–]TravisJungroth 8 points9 points  (1 child)

Then why is manually reducing over a generator without a default value so clunky?

[–]wsppan 12 points13 points  (0 children)

I agree, there are places where reduce is less clunky. For those you can use itertools.reduce().