小编Ser*_*ejo的帖子

如何删除包含我指定的字符以外的字符的行?

我有一个包含DNA和随机行的列表,如下所示:

 dnalist=['AGTCCTGCAGTCG', '@#$@#!AG!!ECG']
Run Code Online (Sandbox Code Playgroud)

我想创建一个函数,过滤掉除了字符'A''G''C'或'T'之外的任何行.到目前为止,我的代码有一种非常粗略的过滤方式,很容易被愚弄:

def seperate(B):
    'takes a list and seperates the DNA lines'
    newlist=[]
    for i in B:
      if i[0]=='G'or i[0]=='A' or i[0]=='T' or i[0]=='C':
           newlist.append(i)           
    return newlist
Run Code Online (Sandbox Code Playgroud)

如果有人能指出一些有关python数据操作的有用教程,那也很棒.谢谢!!!

python string dictionary bioinformatics python-3.x

3
推荐指数
1
解决办法
77
查看次数

标签 统计

bioinformatics ×1

dictionary ×1

python ×1

python-3.x ×1

string ×1