Best way for permutating using multiple lists?

Jon Clements joncle at googlemail.com
Fri Nov 6 08:39:44 EST 2009


On Nov 6, 1:32 pm, hob <cokofree... at 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.



More information about the Python-list mailing list