|
|
|
|
|
by e-dard
5209 days ago
|
|
I prefer "short but to the point". This is instinctively what I threw in iPython before looking past first snippet: print reduce(lambda x, y: x*y, xrange(2, 6+1))
As a newish Python guy (5 months), I'm interested as to why the preferable solution seems to be to import operator and use the multiplication function? (I'm purposely ignoring the more preferable call to the C library) |
|
1) The Python community doesn't really like lambdas. It's almost always considered better style to declare a named function, even if it's a short one-liner. If it's already available in the standard library, use that instead of re-implementing it as an unnecessary lambda.
2) This is an adaptation of jokes that have been made about many languages before Python, so the code isn't very Pythonic to start with. Most of the complex ones have errors that prevent them from running, they're just for comedic effect.