[docs] Bug in part 5 of the Python 3 tutorial

Anton Eliasson devel at antoneliasson.se
Wed Jul 18 15:34:17 CEST 2012


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-comprehensions); 
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



More information about the docs mailing list