2 ms·
Coming from Ruby it's easier to use map, because it's what Ruby's standard library offers. However comprehensions are not that harder when one finally decides
by pmontra 10y ago
Coming from Ruby it's easier to use map, because it's what Ruby's standard library offers.
However comprehensions are not that harder when one finally decides to understand how they work. Not as readable as map() IMHO. Example:
Ruby
[1, 2, 3].map {|x| x*x} # object.method(args)
vs Python
[x*x for x in [1, 2, 3]]
where we have the function first, then the definition of the variable, then the data. This is the opposite of the object.method OO notation and using a variable before defining it is not what we usually do. But it's almost the usual mathematical notation "for i in set do f(i)" with the function at the beginning.
Not a big deal.
About a problem raised in a comment of the post (which is from 2009): this is Guido (2009) about the lack of tail call optimization in Python http://neopythonic.blogspot.it/2009/04/tail-recursion-elimination.html http://neopythonic.blogspot.it/2009/04/tail-recursion-elimin...