PEP-xxx: Unification of for statement and list-comp syntax

George Sakkis george.sakkis at gmail.com
Sun May 21 17:40:33 EDT 2006


Felipe Almeida Lessa wrote:

> Em Dom, 2006-05-21 às 11:52 -0700, gangesmaster escreveu:
> > > Today you can archive the same effect (but not necessarily with the same
> > > performance) with:
> > >
> > > for node in (x for x in tree if x.haschildren()):
> > >     <do something with node>
> >
> > true, but it has different semantic meanings
> >
>
> I know, that's also why I don't oppose the PEP.
>
> --
> Felipe.

I guess the main objections will be that:

1) It doesn't buy you much compared to:
for node in tree:
    if  node.haschildren():
        <do something with node>

2) "There should be one and preferably only one way to do it."
List/genexp comprehensions don't allow larger statement blocks anyway,
so that's not a problem for them.

George




More information about the Python-list mailing list