[Python-Dev] Please Vote -- Generator Comprehensions (original) (raw)

Raymond Hettinger python@rcn.com
Wed, 6 Mar 2002 13:23:10 -0500


This is a multi-part message in MIME format.

------=_NextPart_000_006B_01C1C512.0F85E180 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

After about 30 reviewers, the comments on PEP 279, Enhanced Generators, = have slowed to a trickle. The most universally liked part of the proposal is the addition of = generator comprehensions. No negative feedback was received on generator comprehensions; however, = one person wanted to go further and add restartability; also, there was = a little heartburn about why the existing list comprehensions expose = their looping variable.

Before I send generator comprehension portion to Guido for = pronouncement, I would like to get all of your votes +1 or -1 on just = the part about Generator Comprehensions.

Everyone, please vote +1 or -1.=20

Thank you,

Raymond Hettinger

Here is the proposal in a nutshell:

If a list comprehension starts with a 'yield' keyword, then
express the comprehension with a generator.  For example:

    g =3D [yield (len(line),line)  for line in file  if len(line)>5]
    print g.next()

This would be implemented as if it had been written:

    def __tempGenComp(self):
        for line in file:
            if len(line) > 5:
                yield (len(line), line)
    g =3D __tempGenComp()
    print g.next()

The full PEP is at http://python.sourceforge.net/peps/pep-0279.html. The PEP has a full discussion of the restartability issue, an analysis of why the loop variable should not be exposed,=20 and thoughts on why the syntax is appropriate. It represents the collective wisdom of all the review comments submitted to-date.

------=_NextPart_000_006B_01C1C512.0F85E180 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

After about 30 reviewers, the comments = on PEP 279,=20 Enhanced Generators, have slowed to a trickle.
The most universally liked part of the = proposal is=20 the addition of generator comprehensions.
No negative feedback was received on = generator=20 comprehensions; however, one person wanted to go further and add = restartability;=20 also, there was a little = heartburn about why=20 the existing list comprehensions expose their looping = variable.
 
Before I send generator comprehension = portion to=20 Guido for pronouncement, I would like to get all of your votes +1 or -1 = on just=20 the part about Generator Comprehensions.
 
Everyone, please vote +1 or = -1. 
 
Thank you,
 
 
Raymond Hettinger
 
 
&nbs= p;
Here is the proposal in a = nutshell:
 
    If a list = comprehension starts=20 with a 'yield' keyword, then
    express the = comprehension=20 with a generator.  For=20 example:

        g =3D [yield=20 (len(line),line)  for line in file  if=20 len(line)>5]
        print=20 g.next()

    This would be implemented as if it = had been=20 written:

        def=20 __tempGenComp(self):
        &= nbsp;  =20 for line in=20 file:
          &nbs= p;    =20 if len(line) >=20 5:
           &= nbsp;       =20 yield (len(line), line)
        g = =3D=20 __tempGenComp()
        print=20 g.next()
 
 
 
The full PEP is at [http://python.sourceforge.net/peps/pep-0279.html.
The PEP has a full discussion of the = restartability=20 issue, an
analysis of why the loop variable = should not be=20 exposed,
and thoughts on why the = syntax is=20 appropriate.  It = represents
the collective wisdom of all the review = comments=20 submitted to-date.
 
 

------=_NextPart_000_006B_01C1C512.0F85E180--