zip() or what?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ray Tomes

    zip() or what?

    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

  • Erik Max Francis

    #2
    Re: zip() or what?

    Ray Tomes wrote:
    [color=blue]
    > 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?[/color]

    You wanted

    zip(*x)
    [color=blue]
    > Alternatively, is there a construct to get x[*][i] if you know what I
    > mean?[/color]

    Probably

    [i[1] for i in x]

    or

    map(lambda i: i[1], x)

    --
    Erik Max Francis && [email protected] && http://www.alcyone.com/max/
    __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
    / \ What would physics look like without gravitation?
    \__/ Albert Einstein

    Comment

    Working...