zip() or what?

Ray Tomes rtomes at ihug.co.nz
Thu Jul 3 00:23:04 EDT 2003


Hi all

Many thanks to those that answered my questions about whitespace and ord() 
being reverse of chr(). As well as the 2 things I asked about I learned 
about 5 other useful things.

This I am trying to flip an array around so that the "subscripts" happen 
in the opposite order and reading the docs I thought that zip() did this. 
So I tried it like this:

x=[[0.1,0.2],[1.1,1.2],[2.1,2.2]]
print zip(x)

and what I got was (removing the .0000000001s):

[([0.1, 0.2],), ([1.1, 1.2],), ([2.1, 2.2],)]

which is just my original array with an extra useless level in it.
What I really wanted was this:

[[0.1,1.1,2.1],[0.2,1.2,2.2]]

So my question is how do I do that easily?
And what on earth is zip() doing?

Alternatively, is there a construct to get x[*][i] if you know what I mean?

Have fun

Ray





More information about the Python-list mailing list