Confessions of a Python fanboy

Jan Kaliszewski zuo at
Thu Jul 30 22:23:32 CEST 2009

30-07-2009 o 13:36:49 Masklinn <masklinn at> wrote:

> On 30 Jul 2009, at 06:04 , alex23 wrote:
>> On Jul 30, 1:06 pm, r <rt8... at> wrote:
>>> 2.) the .each method
>>> container.each{|localVar| block}
>>> This method can really cleanup some ugly for loops, although i really
>>> like the readability of for loops.
>> map(lambda localVar: <block>, sequence)
>> or:
>> def usefully_named_func(var):
>>    <block>
>>    return var
>> transformed = [usefully_named_func(v) for v in sequence]
> The issue here is of course that `map` and comprehensions are  
> transformations. `#each` exists for effectful iterations (Ruby has  
> `#map` for the map operation). So the intent expressed by `#each` and  
> `map` isn't the same. Furthermore and this is the most problematic  
> limitation of Python here, `lambda` doesn't allow complex  
> transformations due to its restrictions, so one has to switch to named  
> functions which works but isn't sexy (and tends to lower readability  
> imo).

I don't see any real limitation. What's wrong in:

for localVar in container:

And ruby's container.each is very similar to Python's iter()


Jan Kaliszewski (zuo) <zuo at>

More information about the Python-list mailing list