Confessions of a Python fanboy

Masklinn masklinn at masklinn.net
Thu Jul 30 16:41:57 EDT 2009


On 30 Jul 2009, at 22:23 , Jan Kaliszewski wrote:
> 30-07-2009 o 13:36:49 Masklinn <masklinn at masklinn.net> wrote:
>
>> On 30 Jul 2009, at 06:04 , alex23 wrote:
>>> On Jul 30, 1:06 pm, r <rt8... at gmail.com> 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:
>    block
>
Well what's wrong with using that rather than `map`, `filter` or a  
list comprehension? (and if you don't see what the limitations of  
`lambda` are, you probably very rarely use it)

> And ruby's container.each is very similar to Python's iter()
>
Uh… not at all…




More information about the Python-list mailing list