strange list comprehension on generator

"Martin v. Löwis" martin at v.loewis.de
Wed Aug 29 10:40:49 EDT 2007


> #this does not return the way I would expect. why?

You yield the very same list object all the times. So
when you make a later change, all earlier results will
get changed, too (since they are the same object).
Of course, it won't affect the terminal output, so you
don't see that the older values changed in the example
that you think works as expected.

HTH,
Martin



More information about the Python-list mailing list