小编use*_*969的帖子

计算python中的间隙数

如何计算序列中的间隙数:

例如:

s1='G _ A A T T C A G T T A'
s2='G G _ A _ T C _ G _ _ A'
s3='G A A T T C A G T _ T _'
Run Code Online (Sandbox Code Playgroud)

她的数量'_'8

我尝试以下操作:

def count():
    gap=0
    for i in range(0, len(s1), 3):
        for x,y,z in zip(s1,s2,s3):
            if (x=='_') or (y=='_')or (z=='_') :
                gap=gap+1
        return gap
Run Code Online (Sandbox Code Playgroud)

它给出 6 而不是 8

python count sequence

4
推荐指数
1
解决办法
767
查看次数

将数字列表返回到字符串列表

我想将一个数字列表返回到字符串列表:我有一个列表

copy=[[1,'a'],[55,'b'],[100,'c], [11,d],[66,f]]
Run Code Online (Sandbox Code Playgroud)

如果我有一个列表code=[1,100,100,11,1,66,1] ,结果列表必须类似于以下列表: ['a','c','c','d','a','f','a']然后将其返回到序列seq=['accdafa']

这意味着,我将列表代码中的每个元素与列表副本的元素进行比较.例如,我1从代码中获取元素,并将其与副本列表的元素进行比较 code[0]=1

 if code[0]==copy[0][0]:
                seq.append(copy[0][1])
             else:
                 go to the next element of the list 'copy'
Run Code Online (Sandbox Code Playgroud)

我试试代码:

for j in range(len(code)):

              if code[j]==copy[0][0]:
                seq.append(copy[0][1])
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

IndexError: list index out of range
Run Code Online (Sandbox Code Playgroud)

对于列表的其余元素,同样的事情 code

python string list

2
推荐指数
1
解决办法
61
查看次数

标签 统计

python ×2

count ×1

list ×1

sequence ×1

string ×1