[英]Find all permutations of a string that is variable only at specific positions in Python
我有一個僅在特定位置可變的 DNA 序列,需要找到所有可能的情況:
DNA_seq='ANGK' #N can be T or C and K can be A or G
N=['T','C']
K=['A','G']
結果:
['ATGA','ATGG','ACGA','ACGG']
在線搜索,似乎itertools
的permutations
方法可以用於此目的,但不確定如何實現。 我將不勝感激任何幫助。
from itertools import product
result = [f'A{n}G{k}' for n, k in product(N, K)]
結果:
['ATGA', 'ATGG', 'ACGA', 'ACGG']
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.