Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

Best way for permutating using multiple lists?

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


cokofreedom at gmail

Nov 6, 2009, 5:32 AM

Post #1 of 4 (140 views)
Permalink
Best way for permutating using multiple lists?

if __name__ == '__main__':
permutations = list()
for i in list('def'):
for j in list('abc'):
for k in list('mno'):
for l in list('mno'):
for m in list('wxyz'):
permutations.append()
print '\t'.join("%s" % i for i in permutations)

I'd rather find a way that can perform a permutation over any number
of lists. I know there should be a way of doing this but my head isn't
working today, any advice people?
--
http://mail.python.org/mailman/listinfo/python-list


joncle at googlemail

Nov 6, 2009, 5:39 AM

Post #2 of 4 (138 views)
Permalink
Re: Best way for permutating using multiple lists? [In reply to]

On Nov 6, 1:32 pm, hob <cokofree...@gmail.com> wrote:
> if __name__ == '__main__':
>     permutations = list()
>     for i in list('def'):
>         for j in list('abc'):
>             for k in list('mno'):
>                 for l in list('mno'):
>                     for m in list('wxyz'):
>                         permutations.append()
>     print '\t'.join("%s" % i for i in permutations)
>
> I'd rather find a way that can perform a permutation over any number
> of lists. I know there should be a way of doing this but my head isn't
> working today, any advice people?

itertools.permutations (maybe with itertools.chain)?

hth
Jon.
--
http://mail.python.org/mailman/listinfo/python-list


motoom at xs4all

Nov 6, 2009, 5:43 AM

Post #3 of 4 (138 views)
Permalink
Re: Best way for permutating using multiple lists? [In reply to]

hob wrote:

> any advice people?

import itertools
alt=itertools.product("def","abc","mno","mno","wxyz")


--
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Valloppillil
http://www.catb.org/~esr/halloween/halloween4.html
--
http://mail.python.org/mailman/listinfo/python-list


davea at ieee

Nov 6, 2009, 1:32 PM

Post #4 of 4 (129 views)
Permalink
Re: Best way for permutating using multiple lists? [In reply to]

Michiel Overtoom wrote:
> <div class="moz-text-flowed" style="font-family: -moz-fixed">hob wrote:
>
>> any advice people?
>
> import itertools
> alt=itertools.product("def","abc","mno","mno","wxyz")
>
>
Note to the OP. You called this permutation, but it's not. It's the
crossproduct. Thus itertools.product

DaveA
--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.