Generator Comprehensions? was Re: a break for comprehensions

Paul Prescod paulp at ActiveState.com
Tue Jul 31 15:49:07 EDT 2001


Michael Chermside wrote:
> 
> ...
> 
> How about this:
> 
> def f():
>     for x in g():
>         yield x * 2
> 
> Of course it gives a generator, not a list... but that
> seems to be a reasonable form to represent an infinite sequence.

How about if we combine your ideas:

y = [yield x*2 for x in g()]

-- 
Take a recipe. Leave a recipe.  
Python Cookbook!  http://www.ActiveState.com/pythoncookbook




More information about the Python-list mailing list