python - all possible permutations and combinations problem
漂亮男人
漂亮男人 2017-05-18 10:49:14
0
3
657

For the time being, it is understood as all the combination methods of letters in a string, as follows, a violent and ugly exhaustive method. . . I would like to ask if there is any better method. I have tried several methods in itertools, but none of them meet what I want. Thank you!

base='ATCG'
list=[]
for i in base:
    for j in base:
        for k in base:
            for m in base:
                for l in base:
                    for n in base:
                        seq=i+j+k+m+l+n
                        list.append(seq)
print(len(set(list)))
4096
漂亮男人
漂亮男人

reply all(3)
淡淡烟草味
# coding: utf8
from itertools import product
base = 'ATCG'
result = product(base, repeat=6)  # 因为内容太多, 所以返回生成器, 可以用list方法使其变成列表
print(len(set(result)))


# --- 结果 ----
4096
刘奇
import itertools
len(list(itertools.product(base, repeat=6)))
仅有的幸福
from itertools import product
print(list(map("".join, product("ATCG", repeat=6))))
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template