Message95892
I'd already written then when Benjamin posted his answer, but rather
than waste having written it I'm going to post it anyway :)
You must remember that the purpose of a generator is to evaluate lazily.
Your expression involving the generator would unwrap this way:
def g1():
for y in 'c':
yield x+y
l = []
for x in 'ab':
l.append(g1())
print l
print map(list, l)
If you run this you will note that 'l' is a pair of generator instances.
These are not run until the 'map' is executed. By that point the for
loop has completed, and x has its final value, 'b'. g1 is evaluated
twice, and both times x is 'b', so you get ['bc', 'bc'] |
|
Date |
User |
Action |
Args |
2009-12-02 02:04:03 | r.david.murray | set | recipients:
+ r.david.murray, benjamin.peterson, bogklug |
2009-12-02 02:04:02 | r.david.murray | set | messageid: <1259719442.35.0.719048596446.issue7423@psf.upfronthosting.co.za> |
2009-12-02 02:04:00 | r.david.murray | link | issue7423 messages |
2009-12-02 02:04:00 | r.david.murray | create | |
|