Bug in part 5 of the Python 3 tutorial
Hi! In the Python 3 tutorial about data structures, in the section about nested list comprehensions (http://docs.python.org/py3k/tutorial/datastructures.html#nested-list-compreh...); the zip function is described differently than it works in my installation (Ubuntu 12.04). I'm fairly new to Python so the issue is probably described best using an example: $ python3 Python 3.2.3 (default, May 3 2012, 15:51:42) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> matrix = [ ... [1, 2, 3, 4], ... [5, 6, 7, 8], ... [9, 10, 11, 12], ... ] >>> zip(*matrix) <zip object at 0x1053098> However, in the tutorial the zip function returns a list of tuplets like this: >>> zip(*matrix) [(1, 5, 9), (2, 6, 10), (3, 7, 11), (4, 8, 12)] In order to get that result, I have to do this in my installation: >>> list(zip(*matrix)) [(1, 5, 9), (2, 6, 10), (3, 7, 11), (4, 8, 12)] -- Med vänliga hälsningar / Kindest Regards Anton Eliasson
In the Python 3 tutorial about data structures, in the section about nested list comprehensions (http://docs.python.org/py3k/tutorial/datastructures.html#nested-list-compreh...); the zip function is described differently than it works in my installation (Ubuntu 12.04). I'm fairly new to Python so the issue is probably described best using an example:
$ python3 Python 3.2.3 (default, May 3 2012, 15:51:42) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> matrix = [ ... [1, 2, 3, 4], ... [5, 6, 7, 8], ... [9, 10, 11, 12], ... ] >>> zip(*matrix) <zip object at 0x1053098>
However, in the tutorial the zip function returns a list of tuplets like this:
>>> zip(*matrix) [(1, 5, 9), (2, 6, 10), (3, 7, 11), (4, 8, 12)]
In order to get that result, I have to do this in my installation:
>>> list(zip(*matrix)) [(1, 5, 9), (2, 6, 10), (3, 7, 11), (4, 8, 12)]
Without looking too deep into it, it appears that the example has not been ported to Python 3. Please open an issue in the bug tracker for this. Eli
Hello Anton On Wed, Jul 18, 2012 at 3:34 PM, Anton Eliasson <devel@antoneliasson.se> wrote:
>>> zip(*matrix) <zip object at 0x1053098>
However, in the tutorial the zip function returns a list of tuplets like this:
>>> zip(*matrix) [(1, 5, 9), (2, 6, 10), (3, 7, 11), (4, 8, 12)]
In order to get that result, I have to do this in my installation:
>>> list(zip(*matrix)) [(1, 5, 9), (2, 6, 10), (3, 7, 11), (4, 8, 12)]
Thanks - I've fixed this problem in the Python 3.x documentation some days ago. Regards, -- Sandro Tosi (aka morph, morpheus, matrixhasu) My website: http://matrixhasu.altervista.org/ Me at Debian: http://wiki.debian.org/SandroTosi
participants (3)
-
Anton Eliasson -
Eli Bendersky -
Sandro Tosi