[colug-432] Code check
michael at yanovich.net
michael at yanovich.net
Thu Aug 1 14:41:30 EDT 2013
You can't import itertools^Wessay, that's plagiarism.
http://i.imgur.com/NwNPU.png
On 08/01/2013 01:55 PM, Fandi Peng wrote:
> from itertools import combinations
>
> print combinations( ['DVD', 'dishwasher', 'software', 'tv'], 2)
>
> On Aug 1, 2013 1:39 PM, "Tom Hanlon" <tom at functionalmedia.com
> <mailto:tom at functionalmedia.com>> wrote:
>
> Colug,
>
>
> Writing some python to do the following
>
> Take this list, or any similar list of variable length
>
> ['DVD', 'dishwasher', 'software', 'tv']
>
> And return all two item combinations.
>
> DVD *** dishwasher
> DVD *** software
> DVD *** tv
> dishwasher *** software
> dishwasher *** tv
> software *** tv
>
> My first draft looks like this.
>
> #!/usr/bin/python
> list1 = ['software', 'DVD', 'dishwasher', 'tv'];
> list1.sort();
> print list1;
> for i in range(len(list1)):
> for i2 in range(i+1,len(list1)):
> print list1[i], "***",list1[i2];
>
>
> It works.
>
> Can this be done in a cleaner way ?
> Am I invoking any bad habits ?
> Is there a builtin tool for this ?
>
> Reasons I am doing this..
> 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.
>
> The list of items is an array to hive, I could pass an array of
> arrays if there was a complete "shuffle" I could do on the array
> (word list) . Not finding this I figure that shipping the itemlist
> to python would be the most efficient.
>
> 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.
>
> Thanks, Colug,
>
> Tom
>
>
> _______________________________________________
> colug-432 mailing list
> colug-432 at colug.net <mailto:colug-432 at colug.net>
> http://lists.colug.net/mailman/listinfo/colug-432
>
>
>
> _______________________________________________
> colug-432 mailing list
> colug-432 at colug.net
> http://lists.colug.net/mailman/listinfo/colug-432
>
--
Michael Yanovich
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 901 bytes
Desc: OpenPGP digital signature
Url : http://lists.colug.net/pipermail/colug-432/attachments/20130801/b0f7e97f/attachment.bin
More information about the colug-432
mailing list