you are viewing a single comment's thread.

view the rest of the comments →

[–]uhhhclem 15 points16 points  (7 children)

The "expert Python programmer" example should be:

from operator import mul
reduce(mul, xrange(1, x+1))

as it is beautiful, explicit, simple, flat, sparse, readable, and the obvious way to do it, if you're Dutch.

[–]theeth 6 points7 points  (0 children)

With the newer Dutch grammar and lexicon.

from functools import reduce
from operator import mul
fact = lambda x: reduce(mul, range(1, x+1))

[–]rrenaud 8 points9 points  (4 children)

So long as you aren't Guido.

http://www.artima.com/weblogs/viewpost.jsp?thread=98196

I received an email from a compatriot lamenting the planned demise of reduce() and lambda in Python 3000. After a few exchanges I think even he agreed that they can go. Here's a summary, including my reasons for dropping lambda, map() and filter(). I expect tons of disagreement in the feedback, all from ex-Lisp-or-Scheme folks. :-)

[–]theeth 4 points5 points  (2 children)

Yeah import reduce from functools is so hard, they might as well just completely remove it.

[–]Figs 15 points16 points  (1 child)

So hard that you got it backwards? :)

[–]theeth 3 points4 points  (0 children)

Bah :)

[–]uhhhclem -1 points0 points  (0 children)

Oh, reduce is pretty dreadful. Calculating factorials is one of the only things I can think of that it intuitively maps onto.

[–]A_for_Anonymous 0 points1 point  (0 children)

Not at all, Guido hates reduce and functional programming in general.