generated comprehensions

Oren Tirosh oren-py-l at hishome.net
Tue May 14 04:09:53 EDT 2002


On Mon, May 13, 2002 at 11:31:10PM -0700, Garth T Kidd wrote:
> Has anyone tried to figure out a generator variant on list
> comprehensions? Should all list comprehensions return generators?

PEP 289 by Raymond Hettinger.  http://www.python.org/peps/pep-0289.html

"""
Specification for Generator Comprehensions :

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

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

BDFL Pronouncements

    Generator comprehensions are REJECTED.  The rationale is that the
    benefits are marginal since generators can already be coded
    directly and the costs are high because implementation and
    maintenance require major efforts with the parser.
"""

    RTFP'ly yours

	Oren





More information about the Python-list mailing list