我正在研究一种算法,该算法使用的是肽的领导板,并删除没有特定“分数”的肽。目前,我很难理解为什么我在删除过程中不断出错。我相信这可能与我复制名单有关,然后我在删除过程中使用。但是,我在以前的问题中使用了同样的过程,没有问题,所以我不明白为什么这个特定的实例会抛出一个错误。
def Trim(Leaderboard,Spectra,N):
Scores=[];droplist=[]
for peptide in Leaderboard:
Scores.append(LinearScore(peptide,Spectra))
Leaderboard,Scores = zip(*sorted(zip(Leaderboard, Scores),key=lambda peptide: peptide[1], reverse=True))
Leaderboard=list(Leaderboard);Scores=list(Scores) ### IS THIS WHERE THE PROBLEM IS????
Cutoffscore=Scores[N-1] # Here I am finding the Score of the Nth' peptide (in sorted order)
for peptide,score in zip(Leaderboard,Scores): # iterate through list of tuples
if score<Cutoffscore: # if peptide score is lower than cut off score
droplist.append(peptide) # remove that peptide from the leaderboard
for i in droplist:
Leaderboard.remove(i) ### ERROR THROWN HERE "Error list.remove(x), x not in list"
return Leaderboard # then return what's left of the list编辑:问题出现在程序的其他地方。
发布于 2014-11-07 00:00:44
new_list = [peptide for peptide,score in zip(Leaderboard,Scores) if score >= CutoffScore]是一个更好的方法来实现这一点..。也就是说你应该向后遍历液滴
for i in reversed(droplist):
Leaderboard.remove(i)问题是
考虑一下你有分数[1,5,5,5,5,5,1]的情况.您在液滴中的索引是[0, 6]
但是一旦你弹出0..。没有指数6。你的另一个指数已经转移到5。
https://stackoverflow.com/questions/26791604
复制相似问题