Python permutations of a heterogeneous list element

This is the sequence:

l = [['A', 'G'], 'A', ['A', 'C']]

I need a third sequence of elements for each permutation

all = ['AAA','GAA','AAC','GAC']

I can not understand this! I'm having trouble maintaining the permutation order!

+4
source share
1 answer

Do you want product :

from itertools import product

l = [['A', 'G'], 'A', ['A', 'C']]

print(["".join(p) for p in product(*l)])
+6
source

All Articles