<div dir="ltr"><div><div><div><div>That is sweet !!<br><br></div>Python is nice, <br><br></div>I think what I just did was<br><br></div><div>#!/usr/bin/python<br></div>from colug import experience<br><br>--<br></div>Tom <br>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Aug 1, 2013 at 1:55 PM, Fandi Peng <span dir="ltr">&lt;<a href="mailto:fandi.814@gmail.com" target="_blank">fandi.814@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">from itertools import combinations</p>
<p dir="ltr">print combinations( [&#39;DVD&#39;, &#39;dishwasher&#39;, &#39;software&#39;, &#39;tv&#39;],  2)</p>
<div class="gmail_quote"><div><div class="h5">On Aug 1, 2013 1:39 PM, &quot;Tom Hanlon&quot; &lt;<a href="mailto:tom@functionalmedia.com" target="_blank">tom@functionalmedia.com</a>&gt; wrote:<br type="attribution"></div>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
<div dir="ltr"><div><div><div><div><div><div><div><div><div><div><div>Colug, <br><br><br></div>Writing some python to do the following<br><br>Take this list, or any similar list of variable length<br><br>[&#39;DVD&#39;, &#39;dishwasher&#39;, &#39;software&#39;, &#39;tv&#39;]<br>


<br>And return all two item combinations. <br><br>DVD *** dishwasher<br>DVD *** software<br>DVD *** tv<br>dishwasher *** software<br>dishwasher *** tv<br>software *** tv<br><br></div>My first draft looks like this. <br><br>


#!/usr/bin/python<br>list1 = [&#39;software&#39;, &#39;DVD&#39;, &#39;dishwasher&#39;, &#39;tv&#39;];<br>list1.sort();<br>print list1;<br>for i in range(len(list1)):<br>    for i2 in range(i+1,len(list1)):<br>        print list1[i], &quot;***&quot;,list1[i2];<br>


<br><br></div>It works. <br><br></div>Can this be done in a cleaner way ? <br></div>Am I invoking any bad habits ? <br></div>Is there a builtin tool for this ? <br><br></div>Reasons I am doing this..<br></div>hive the hadoop SQL to Map Reduce translator has ngrams, that allow splitting strings into configurable length substrings. That is sorta cool, but I want all possible pairs, not just consecutive pairs. <br>


<br></div>The list of items is an array to hive, I could pass an array of arrays if there was a complete &quot;shuffle&quot; I could do on the array (word list) . Not finding this I figure that shipping the itemlist to python would be the most efficient. <br>


<br></div>So that is the use case, but help with the python in terms of a quick sanity check is what I need. Unless you happen to be doing word co-occurrence in hive and have some insight there. <br><br></div>Thanks, Colug, <br>


<br>Tom <br><div><div><div><div><div><div><div><div><div><br></div></div></div></div></div></div></div></div></div></div>
<br></div></div>_______________________________________________<br>
colug-432 mailing list<br>
<a href="mailto:colug-432@colug.net" target="_blank">colug-432@colug.net</a><br>
<a href="http://lists.colug.net/mailman/listinfo/colug-432" target="_blank">http://lists.colug.net/mailman/listinfo/colug-432</a><br>
<br></blockquote></div>
<br>_______________________________________________<br>
colug-432 mailing list<br>
<a href="mailto:colug-432@colug.net">colug-432@colug.net</a><br>
<a href="http://lists.colug.net/mailman/listinfo/colug-432" target="_blank">http://lists.colug.net/mailman/listinfo/colug-432</a><br>
<br></blockquote></div><br></div>