what is the best idiom to perform the opposite of "zip"? (besides "unfold")

Discussion in 'Ruby' started by bwv549, Oct 2, 2012.

  1. bwv549

    bwv549 Guest

    I need to turn some list of pairs into two arrays (the opposite of zipping two arrays together). There is a solution using "unfold" here (http://weblog.raganwald.com/2007/11/really-useful-anamorphisms-in-ruby.html) but that seems like more than what I want for this task.

    I want to turn this:
    [[1,2][3,4],[5,6]]

    Into:
    [[1,3,5], [2,4,6]]

    What's the best ruby idiom for doing this task. Can it be generalized for triplets, quadruplets, etc.?

    Or, if you use unfold, is there a particular gem you use and does it take amajor performance hit?
     
    bwv549, Oct 2, 2012
    #1
    1. Advertising

  2. bwv549

    bwv549 Guest

    Array#transpose

    And I've used and recommended this many times...
     
    bwv549, Oct 2, 2012
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Hunsley
    Replies:
    1
    Views:
    626
    Andrew Thompson
    Sep 16, 2004
  2. Replies:
    0
    Views:
    1,804
  3. HARI OM
    Replies:
    0
    Views:
    17,495
    HARI OM
    May 3, 2005
  4. sunil_varma
    Replies:
    1
    Views:
    1,281
  5. opposite of zip()?

    , Dec 15, 2007, in forum: Python
    Replies:
    11
    Views:
    1,606
    Rich Harkins
    Dec 17, 2007
Loading...

Share This Page