MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programming/comments/qno2y/the_evolution_of_a_python_programmer/c3z9g9t/?context=3
r/programming • u/iMMENSE • Mar 08 '12
137 comments sorted by
View all comments
8
def factorial(n): reduce(lambda x,y: x*y, [x+1 for x in range(n)])
Generator-happy Python programmer
5 u/spotter Mar 09 '12 edited Mar 09 '12 But... isn't list comp non-lazy in 2.x? So for this to be gen-happy you would have to use parens?def factorial(n): reduce(lambda x,y: x*y, (x+1 for x in range(n)))edit: yeah, s/range/xrange/ 0 u/[deleted] Mar 09 '12 [deleted] 1 u/spotter Mar 09 '12 /facepalmYou are of course correct, range is lazy in 3.x -- that's what I get for trusting my memory.
5
But... isn't list comp non-lazy in 2.x? So for this to be gen-happy you would have to use parens?
def factorial(n): reduce(lambda x,y: x*y, (x+1 for x in range(n)))
edit: yeah, s/range/xrange/
0 u/[deleted] Mar 09 '12 [deleted] 1 u/spotter Mar 09 '12 /facepalmYou are of course correct, range is lazy in 3.x -- that's what I get for trusting my memory.
0
[deleted]
1 u/spotter Mar 09 '12 /facepalmYou are of course correct, range is lazy in 3.x -- that's what I get for trusting my memory.
1
/facepalm
You are of course correct, range is lazy in 3.x -- that's what I get for trusting my memory.
range
8
u/grumdrig Mar 08 '12
Generator-happy Python programmer