code-example doesn't work as displayed in documentation
http://docs.python.org/py3k/tutorial/datastructures.html#nested-list-compreh... the code-example in the last paragraph of nested list comprehensions doesn't work like displayed. displayed:
zip(*matrix) [(1, 5, 9), (2, 6, 10), (3, 7, 11), (4, 8, 12)]
but works like that:
zip(*matrix) <zip object at 0x7fd9d8a660e0>
to make it work like displayed i had to type:
list(zip(*matrix)) [(1, 5, 9), (2, 6, 10), (3, 7, 11), (4, 8, 12)]
i guess the example was just copied from the 2.7.3 python documentation because it worked like displayed with Python 2.7.3, but not with Python 3.2.3 Regards Martin
Hello Martin, On Thu, Aug 2, 2012 at 8:11 AM, Martin <mpc4@gmx.com> wrote:
zip(*matrix) <zip object at 0x7fd9d8a660e0>
to make it work like displayed i had to type:
list(zip(*matrix)) [(1, 5, 9), (2, 6, 10), (3, 7, 11), (4, 8, 12)]
zip() in Python 3.x returns an iterator, so we need to make a list from it - I've just fixed for python 3.2 and 3.3 Regards, -- Sandro Tosi (aka morph, morpheus, matrixhasu) My website: http://matrixhasu.altervista.org/ Me at Debian: http://wiki.debian.org/SandroTosi
participants (2)
-
Martin
-
Sandro Tosi