list-display semantics?

Uwe Hoffmann nospam at nospam.de
Sun Jun 10 14:50:44 EDT 2001


jainweiwu wrote:
> 
> Hi all:
> I tried the one-line command in a interaction mode:
> [x for x in [1, 2, 3], y for y in [4, 5, 6]]

actually is: [ x for x in [[1, 2, 3], y] for y in [4, 5, 6] ] 


> and the result surprised me, that is:
> [[1,2,3],[1,2,3],[1,2,3],9,9,9]
> Who can explain the behavior?
> Since I expected the result should be:
> [[1,4],[1,5],[1,6],[2,4],...]

[ [x,y] for x in [1, 2, 3] for y in [4, 5, 6] ] 

> --
> Pary All Rough Yet.
> parywu at seed.net.tw

regards uwe



More information about the Python-list mailing list