简体   繁体   中英

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!

You want the product :

from itertools import product

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM