Too much code - slicing

Andreas Waldenburger usenot at geekmail.INVALID
Thu Sep 23 17:38:33 CEST 2010


On 23 Sep 2010 03:54:52 GMT Seebs <usenet-nospam at seebs.net> wrote:

> On 2010-09-23, Steven D'Aprano <steve-REMOVE-THIS at cybersource.com.au>
> wrote:
> [snip]
> > I don't see anyone bitching about:
> 
> > for x in seq:
> >     if x:
> >         f(x)
> 
> > vs 
> 
> > [f(x) for x in seq if x]
> 
> In my case, that's because I only ran into that syntax about an hour
> and a half ago.  I have the same basic objection to it.  If it were:
> 
> [for x in seq: if x: f(x)]
> 
> I'd find it substantially easier to understand.
> 
> I don't generally like constructs where important structural
> information comes late in the construct. [snip]

I think that is precisely the reason that the elements of the list come
*first* in the list comprehension expression. The foremost idea of list
comprehensions is "build a list", while the idea of a for-loop is
"iterate over something".

/W

-- 
INVALID? DE!




More information about the Python-list mailing list