rna = 'U A U G C U A A U U C G A U A A C C G A'
rna = ''.join(rna.split()) # This just converts it to a string with no whitspaces.
# Don't iterate over the whole string, stop when reaching len(rna)-2
for i in range(0,len(rna)-2):
# Break and only keep everything from here on
# Compare the current 3 letters
if rna[i:i+3] == 'AUG':
out = rna[i:]
break # End the loop here
print out
# 'AUGCUAAUUCGAUAACCGA'
也许用
index
?你知道吗有些事情是错误的:
AUG
不是从n * 3
(其中n
是任何整数)的索引开始,则不应使用3的步长,否则会丢失它。你知道吗[start:stop]
语法排除字符串的范围。你知道吗例如:
相关问题 更多 >
编程相关推荐