strange list comprehension on generator

Bjoern Schliessmann usenet-mail-0306.20.chr0n0ss at spamgourmet.com
Wed Aug 29 10:38:54 EDT 2007


No greeting, no text? Pity.

Roland Puntaier wrote:

> def changeOne(aa,idx):
>   aa[idx]=not aa[idx]
>   yield aa
>   for i in range(idx):
>     for x in changeOne(aa,i):
>       yield x
> 
> def changeOneOrder(aa):
>   yield aa
>   for i in range(len(aa)):
>     for x in changeOne(aa,i):
>       yield x

Okay, two generator definitions.
 
> a=[False]*3
> og=changeOneOrder(a)
> #this does not return the way I would expect. why?

What do you expect? You created a generator object and bound it
to "og".

Please always state what you expect and what really happens. Fortune
telling is not one of my hobbies (and I think I'm not alone with
that).

Regards,


Björn

-- 
BOFH excuse #284:

Electrons on a bender




More information about the Python-list mailing list