3 ms·
From the example http://canonical.org/~kragen/sw/netbook-misc-devel/rotcube.py http://canonical.org/~kragen/sw/netbook-misc-devel/rotcube.p... how does this for
by _glass 4y ago
From the example http://canonical.org/~kragen/sw/netbook-misc-devel/rotcube.py http://canonical.org/~kragen/sw/netbook-misc-devel/rotcube.p...
how does this for expression work?
cube = [(x, y, z) for x in -1, 1 for y in -1, 1 for z in -1, 1]
My interpreter can't do it, and I don't really understand how this is supposed to work :)
Thanks!
- helpyhelperx 4y agoIt works on Python38 with cube = [(x, y, z) for x in range(-1, 1) for y in range(-1, 1) for z in range(-1, 1)] I had the same question. Maybe it's a Python2 construct?
- _glass 4y agothanks, this is working. now I also get the math.
- kragen 4y agoSorry, I wrote that 10 years ago. I guess Python 3 requires you to say "for x in (-1, 1) for y in (-1, 1) for z in (-1, 1)", while Python 2 parsed those as tuples even without the parens. The parens make the code clearer anyway.