Rosalind第23题:Enumerating k-mers Lexicographically

Problem

Assume that an alphabet  has a predetermined order; that is, we write the alphabet as a permutation , where . For instance, the English alphabet is organized as .

Given two strings  and  having the same length , we say that  precedes  in the lexicographic order (and write ) if the first symbol  that doesn't match  satisfies  in .

Given: A collection of at most 10 symbols defining an ordered alphabet, and a positive integer  ().

Return: All strings of length  that can be formed from the alphabet, ordered lexicographically (use the standard order of symbols in the English alphabet).

假设字母 具有预定顺序;也就是说,我们将字母写成一个置换,其中。例如,英语字母组织为。 

给定两个字符串,并具有相同的长度,我们说先于在字典顺序(和写),如果第一个符号不匹配满足的。

给定:最多包含10个符号的集合,定义一个有序字母和一个正整数()。

返回值:可以由字母组成的所有长度的字符串,按字典顺序排序(使用英语字母中符号的标准顺序)。

 

Sample Dataset

A C G T
2

Sample Output

AA
AC
AG
AT
CA
CC
CG
CT
GA
GC
GG
GT
TA
TC
TG
TT

python解决方案

import itertools
# with open("../data/rosalind_lexf.txt", 'r') as f:
#     string = f.readline().split()
#     n = int(f.readline().strip())
string = 'ACGT'
n = 2
result = list(itertools.product(string, repeat = n))
print("\n".join(["".join(x) for x in result]))

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值