def testing(dnaStrand):
protein = []
start = dnaStrand.find('ATG')
end = len(dnaStrand)
totalLength = dnaStrand[start:end]
remove = totalLength.split('TAG')
protein = [[i] for i in remove]
print(protein)
protein is a list of lists - Each time 'TAG' appears in the given string a new inner list is created and contains all characters up till the next 'TAG'. I want my inner lists to be groups of three characters. For example:
testing('ATGABCTAGDEFHIJTAGKLM')
returns:
[['ATGABC'], ['DEFHIJ'], ['KLM']]
What I need:
[['ATG', 'ABC'], ['DEF', 'HIJ'], ['KLM']]
输入可以是字母的任意组合,可以有无限的内部列表,内部列表中可以有无限的项目
您可以使用列表理解,请尝试以下方法:
试试这个
编辑:
输出
试试这个:
相关问题 更多 >
编程相关推荐