From: Brian Candler Date: 2009-07-14T23:48:56+09:00 Subject: Re: Elegant solution for inverting zip? Gregory Brown wrote: > On Tue, Jul 14, 2009 at 9:27 AM, Gregory > Brown wrote: > > >> require "matrix" >> b = Matrix[*a].column_vectors.map(&:to_a) > > *facepalm* Array#transpose is what I needed, I can't believe I forgot > that. Thanks goes to David Black via IM. That's funny - I was just trying to do more or less the same thing the other day. Given an array of [k,v] pairs, I needed to turn it into an array of k's and an array of v's. I searched for a built-in method to do this, couldn't find it, so went for the obvious solution: ks = src.collect { |k,v| k } vs = src.collect { |k,v| v } But now I know a better way: ks, vs = src.transpose Thanks for sharing! -- Posted via http://www.ruby-forum.com/.