<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: zip vs transpose</title>
	<atom:link href="http://drnicwilliams.com/2006/10/03/zip-vs-transpose/feed/" rel="self" type="application/rss+xml" />
	<link>http://drnicwilliams.com/2006/10/03/zip-vs-transpose/</link>
	<description>Ruby makes Rails, Javascript makes Ajax, Dr Nic makes Magic</description>
	<lastBuildDate>Fri, 30 Jul 2010 18:50:41 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: AegisThorne</title>
		<link>http://drnicwilliams.com/2006/10/03/zip-vs-transpose/comment-page-1/#comment-2047</link>
		<dc:creator>AegisThorne</dc:creator>
		<pubDate>Tue, 02 Jan 2007 04:00:28 +0000</pubDate>
		<guid isPermaLink="false">http://drnicwilliams.com/2006/10/03/zip-vs-transpose/#comment-2047</guid>
		<description>I&#039;m fond of 

class Array
  def hash_with(values)
    Hash[*self.zip(values).flatten]
  end
end

[1,2,3].hash_with([&quot;2&quot;, &quot;3&quot;,&quot;4&quot;])
=&gt; {1=&gt;&quot;2&quot;, 2=&gt;&quot;3&quot;, 3=&gt;&quot;4&quot;}</description>
		<content:encoded><![CDATA[<p>I&#8217;m fond of </p>
<p>class Array<br />
  def hash_with(values)<br />
    Hash[*self.zip(values).flatten]<br />
  end<br />
end</p>
<p>[1,2,3].hash_with(["2", "3","4"])<br />
=&gt; {1=&gt;&#8221;2&#8243;, 2=&gt;&#8221;3&#8243;, 3=&gt;&#8221;4&#8243;}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: evan</title>
		<link>http://drnicwilliams.com/2006/10/03/zip-vs-transpose/comment-page-1/#comment-312</link>
		<dc:creator>evan</dc:creator>
		<pubDate>Fri, 06 Oct 2006 19:27:29 +0000</pubDate>
		<guid isPermaLink="false">http://drnicwilliams.com/2006/10/03/zip-vs-transpose/#comment-312</guid>
		<description>Hey, I never thought of it as a zipper. That&#039;s great. I would use zip with some frequency but just sort of in an intuitive way. I didn&#039;t have any rigorous explanation of what it did. 

To me, &quot;zip&quot; in software context means compression. Thus the confusion.</description>
		<content:encoded><![CDATA[<p>Hey, I never thought of it as a zipper. That&#8217;s great. I would use zip with some frequency but just sort of in an intuitive way. I didn&#8217;t have any rigorous explanation of what it did. </p>
<p>To me, &#8220;zip&#8221; in software context means compression. Thus the confusion.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dr Nic</title>
		<link>http://drnicwilliams.com/2006/10/03/zip-vs-transpose/comment-page-1/#comment-304</link>
		<dc:creator>Dr Nic</dc:creator>
		<pubDate>Wed, 04 Oct 2006 12:40:47 +0000</pubDate>
		<guid isPermaLink="false">http://drnicwilliams.com/2006/10/03/zip-vs-transpose/#comment-304</guid>
		<description>@bob - ooh nice. That&#039;s +1 for zip.</description>
		<content:encoded><![CDATA[<p>@bob &#8211; ooh nice. That&#8217;s +1 for zip.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bob Hutchison</title>
		<link>http://drnicwilliams.com/2006/10/03/zip-vs-transpose/comment-page-1/#comment-303</link>
		<dc:creator>Bob Hutchison</dc:creator>
		<pubDate>Wed, 04 Oct 2006 12:32:36 +0000</pubDate>
		<guid isPermaLink="false">http://drnicwilliams.com/2006/10/03/zip-vs-transpose/#comment-303</guid>
		<description>Zip also takes a block like so:

irb(main):001:0&gt; (1..3).zip(4..6) { &#124; a, b &#124; puts &quot;a: #{a}, b: #{b}&quot;; a + b }
a: 1, b: 4
a: 2, b: 5
a: 3, b: 6
=&gt; nil


This can be handy.</description>
		<content:encoded><![CDATA[<p>Zip also takes a block like so:</p>
<p>irb(main):001:0&gt; (1..3).zip(4..6) { | a, b | puts &#8220;a: #{a}, b: #{b}&#8221;; a + b }<br />
a: 1, b: 4<br />
a: 2, b: 5<br />
a: 3, b: 6<br />
=&gt; nil</p>
<p>This can be handy.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dr Nic</title>
		<link>http://drnicwilliams.com/2006/10/03/zip-vs-transpose/comment-page-1/#comment-299</link>
		<dc:creator>Dr Nic</dc:creator>
		<pubDate>Tue, 03 Oct 2006 17:38:04 +0000</pubDate>
		<guid isPermaLink="false">http://drnicwilliams.com/2006/10/03/zip-vs-transpose/#comment-299</guid>
		<description>@greg - I agree that this is a great solution for readability sake.

@paul - &quot;interlace&quot; IS such a nice name :)</description>
		<content:encoded><![CDATA[<p>@greg &#8211; I agree that this is a great solution for readability sake.</p>
<p>@paul &#8211; &#8220;interlace&#8221; IS such a nice name <img src='http://drnicwilliams.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Greg Spurrier</title>
		<link>http://drnicwilliams.com/2006/10/03/zip-vs-transpose/comment-page-1/#comment-298</link>
		<dc:creator>Greg Spurrier</dc:creator>
		<pubDate>Tue, 03 Oct 2006 17:21:10 +0000</pubDate>
		<guid isPermaLink="false">http://drnicwilliams.com/2006/10/03/zip-vs-transpose/#comment-298</guid>
		<description>I prefer the zip version.  It&#039;s easier for me to get my head around &quot;zip these two things together&quot; than treating arrays like vectors and doing matrix operations on them.

But, I like it even better when I don&#039;t have to think about it at all.  Why not just extend the Hash class with a from_keys_and_values class method?


class Hash
  def Hash.from_keys_and_values(k_array, v_array)
    Hash[*k_array.zip(v_array).flatten]
  end
end


Then it&#039;s just:


irb(main):011:0&gt; k = %w(a b c)
=&gt; [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;]
irb(main):012:0&gt; v = [1, 2, 3]
=&gt; [1, 2, 3]
irb(main):013:0&gt; Hash.from_keys_and_values(k,v)
=&gt; {&quot;a&quot;=&gt;1, &quot;b&quot;=&gt;2, &quot;c&quot;=&gt;3}
</description>
		<content:encoded><![CDATA[<p>I prefer the zip version.  It&#8217;s easier for me to get my head around &#8220;zip these two things together&#8221; than treating arrays like vectors and doing matrix operations on them.</p>
<p>But, I like it even better when I don&#8217;t have to think about it at all.  Why not just extend the Hash class with a from_keys_and_values class method?</p>
<p>class Hash<br />
  def Hash.from_keys_and_values(k_array, v_array)<br />
    Hash[*k_array.zip(v_array).flatten]<br />
  end<br />
end</p>
<p>Then it&#8217;s just:</p>
<p>irb(main):011:0&gt; k = %w(a b c)<br />
=&gt; ["a", "b", "c"]<br />
irb(main):012:0&gt; v = [1, 2, 3]<br />
=&gt; [1, 2, 3]<br />
irb(main):013:0&gt; Hash.from_keys_and_values(k,v)<br />
=&gt; {&#8220;a&#8221;=&gt;1, &#8220;b&#8221;=&gt;2, &#8220;c&#8221;=&gt;3}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Battley</title>
		<link>http://drnicwilliams.com/2006/10/03/zip-vs-transpose/comment-page-1/#comment-296</link>
		<dc:creator>Paul Battley</dc:creator>
		<pubDate>Tue, 03 Oct 2006 15:25:52 +0000</pubDate>
		<guid isPermaLink="false">http://drnicwilliams.com/2006/10/03/zip-vs-transpose/#comment-296</guid>
		<description>Déjà vu! #ruby-lang IRC logs from 2005 (ThreeDayMonk is me):

[ThreeDayMonk] I can think of many ways to turn a1 = %w[foo bar baz]; a2 = [1,2,3] into {&#039;foo&#039;=&gt;1, &#039;bar&#039;=&gt;2, &#039;baz&#039;=&gt;3}, but I&#039;m wondering if there&#039;s not a really simple way
[chris2]        Hash[*a1.zip(a2)] ?
[ThreeDayMonk]  ah, zip interleaves them?  that&#039;s what I couldn&#039;t remember
[chris2]        i think so
[chris2]        maybe you need a flatten
[chris2]        yeah
[ThreeDayMonk]  yes
[chris2]        Hash[*[1,2,3].zip([4,5,6]).flatten]
[chris2]        which gets us to the question why Hash[*hash.to_a] doesnt work :)
[ThreeDayMonk]  I really wish that some of the buitl-in methods had more obvious names - it would take me less time to type &#039;interleave&#039; than to work out that &#039;zip&#039; is the method I need
[Ben]   I would probably go for [a1, a2].transpose
[Ben]   .flatten
[ThreeDayMonk]  Ben: yeah, transpose is nice
[ThreeDayMonk]  it has a matrix parallel
[chris2]        ThreeDayMonk: but it&#039;s called zip in haskell too! :P
[ThreeDayMonk]  all the more reason not to do it :-)
[ThreeDayMonk]  actually, I kind of get it
[ThreeDayMonk]  like the teeth of a zip
[chris2]        yeah
[chris2]        makes perfect sense. you just need to know it exists
[chris2]        it&#039;s not really interleave
[ThreeDayMonk]  interlace would be more accurate</description>
		<content:encoded><![CDATA[<p>Déjà vu! #ruby-lang IRC logs from 2005 (ThreeDayMonk is me):</p>
<p>[ThreeDayMonk] I can think of many ways to turn a1 = %w[foo bar baz]; a2 = [1,2,3] into {&#8216;foo&#8217;=&gt;1, &#8216;bar&#8217;=&gt;2, &#8216;baz&#8217;=&gt;3}, but I&#8217;m wondering if there&#8217;s not a really simple way<br />
[chris2]        Hash[*a1.zip(a2)] ?<br />
[ThreeDayMonk]  ah, zip interleaves them?  that&#8217;s what I couldn&#8217;t remember<br />
[chris2]        i think so<br />
[chris2]        maybe you need a flatten<br />
[chris2]        yeah<br />
[ThreeDayMonk]  yes<br />
[chris2]        Hash[*[1,2,3].zip([4,5,6]).flatten]<br />
[chris2]        which gets us to the question why Hash[*hash.to_a] doesnt work <img src='http://drnicwilliams.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
[ThreeDayMonk]  I really wish that some of the buitl-in methods had more obvious names &#8211; it would take me less time to type &#8216;interleave&#8217; than to work out that &#8216;zip&#8217; is the method I need<br />
[Ben]   I would probably go for [a1, a2].transpose<br />
[Ben]   .flatten<br />
[ThreeDayMonk]  Ben: yeah, transpose is nice<br />
[ThreeDayMonk]  it has a matrix parallel<br />
[chris2]        ThreeDayMonk: but it&#8217;s called zip in haskell too! <img src='http://drnicwilliams.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /><br />
[ThreeDayMonk]  all the more reason not to do it <img src='http://drnicwilliams.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /><br />
[ThreeDayMonk]  actually, I kind of get it<br />
[ThreeDayMonk]  like the teeth of a zip<br />
[chris2]        yeah<br />
[chris2]        makes perfect sense. you just need to know it exists<br />
[chris2]        it&#8217;s not really interleave<br />
[ThreeDayMonk]  interlace would be more accurate</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dr Nic</title>
		<link>http://drnicwilliams.com/2006/10/03/zip-vs-transpose/comment-page-1/#comment-294</link>
		<dc:creator>Dr Nic</dc:creator>
		<pubDate>Tue, 03 Oct 2006 11:57:53 +0000</pubDate>
		<guid isPermaLink="false">http://drnicwilliams.com/2006/10/03/zip-vs-transpose/#comment-294</guid>
		<description>Perhaps an alias &lt;code&gt;interlace&lt;/code&gt; would be helpful.</description>
		<content:encoded><![CDATA[<p>Perhaps an alias <code>interlace</code> would be helpful.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Battley</title>
		<link>http://drnicwilliams.com/2006/10/03/zip-vs-transpose/comment-page-1/#comment-293</link>
		<dc:creator>Paul Battley</dc:creator>
		<pubDate>Tue, 03 Oct 2006 11:39:31 +0000</pubDate>
		<guid isPermaLink="false">http://drnicwilliams.com/2006/10/03/zip-vs-transpose/#comment-293</guid>
		<description>I think that zip, like inject, is one of those Ruby methods whose name and function is inspired by another language. In my case, I didn&#039;t start using it in Ruby until I came across it in Haskell.

If you think about it, the name &#039;zip&#039; does make some sense - it&#039;s like the teeth of a zip (zipper) meshing together - but it&#039;s not necessarily the image that springs to mind when you first encounter it.</description>
		<content:encoded><![CDATA[<p>I think that zip, like inject, is one of those Ruby methods whose name and function is inspired by another language. In my case, I didn&#8217;t start using it in Ruby until I came across it in Haskell.</p>
<p>If you think about it, the name &#8216;zip&#8217; does make some sense &#8211; it&#8217;s like the teeth of a zip (zipper) meshing together &#8211; but it&#8217;s not necessarily the image that springs to mind when you first encounter it.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
