调整Fucntion以找到一个以上的位置
我创建了此功能,并在DNA序列中找到了基础的位置。像dna = ['a','g','c','g','t','a','g','t','t','c','g',a','t ','c','a','a','t','t','a','t','a','c','g',g',a','','t','t',t',t',' 'c','g','g','g', 't','a','t']。我需要它在一次“ A''T”之类的时间找到一个以上的基础。谁能帮忙?
def position(list, value):
pos = []
for n in range(len(list)):
if list[n] == value:
pos.append(n)
return pos
I created this function and it finds the location of the base in a dna sequences. Like dna = ['A', 'G', 'C', 'G', 'T', 'A', 'G', 'T', 'C', 'G', 'A', 'T', 'C', 'A', 'A', 'T', 'T', 'A', 'T', 'A', 'C', 'G', 'A', 'T', 'C', 'G', 'G', 'G', 'T', 'A', 'T']. I need it to find more than one base at a time like 'A''T'. Can anyone help?
def position(list, value):
pos = []
for n in range(len(list)):
if list[n] == value:
pos.append(n)
return pos
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以将DNA序列用作字符串,然后使用正则序列:
You can work with the dna sequence as a string, and then use regex:
旁注,很好,不要将关键字用于可变名称。列表是Python关键字
side note, good not to use keywords for variable names. list is a python keyword
您绝对应该使用Python内置功能。例如,
如果您考虑一对字母对,则可以使用理解查找bigram而不是
位置(list,value)
可以减少到上述:如果您想找到“任一A的位置” '或't',您可以将其指定为条件
You should definitely use Python built-in functions. For instance, instead of
position(list, value)
you could use comprehensionFinding a bigram could be reduced to the above if you consider pairs of letters:
If instead you want to find the positions of either 'A' or 'T', you could just specify that as the condition
Python将有效地找到从任何点开始的字符串的子字符串。
测试用法:
Python will efficiently find a substring of a string starting from any point.
Test usage: