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

Jack Jansen Jack.Jansen@oratrix.com
Wed, 6 Mar 2002 22:21:55 +0100


On woensdag, maart 6, 2002, at 07:23 , Raymond Hettinger wrote:

Here is the proposal in a nutshell: =A0 =A0=A0=A0 If a list comprehension starts with a 'yield' keyword, then =A0=A0=A0 express the comprehension with a generator.=A0 For example:

=A0=A0=A0=A0=A0=A0=A0 g =3D [yield (len(line),line)=A0 for line in = file=A0 if=20 len(line)>5] =A0=A0=A0=A0=A0=A0=A0 print g.next() =A0=A0=A0 This would be implemented as if it had been written: _=A0=A0=A0=A0=A0=A0=A0 def tempGenComp(self): =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 for line in file: =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if len(line) > 5: =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 yield = (len(line), line) _=A0=A0=A0=A0=A0=A0=A0 g =3D tempGenComp() =A0=A0=A0=A0=A0=A0=A0 print g.next()

+1.

Now if you would please comment (or vote +1 or -1) on PEP 278 -=20 Allowing foreign newlines in text input files and modules=20 (universal newline support, for short) then that's another PEP=20 that could move forward. The code has been sitting there with=20 very minor mods for more than 4 months now:-(