jwillis0720
jwillis0720

Reputation: 4477

Python permutations of heterogenous list elements

This is the sequence:

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

I need the three element sequence back for each permutation

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

I can't figure this one out! I'm having trouble retaining the permutation order!

Upvotes: 4

Views: 50

Answers (1)

Padraic Cunningham
Padraic Cunningham

Reputation: 180401

You want the product:

from itertools import product

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

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

Upvotes: 6

Related Questions