我正在使用一种算法,该算法使用肽的排行榜并删除没有特定“分数”的肽。我目前正在努力理解为什么我不断收到有关我的删除过程的错误。我相信它可能必须与我的复制清单,然后我在我的清除过程中使用。不过,我在前面的问题中使用了相同的过程,没有任何问题,所以我不明白为什么这个特定的实例抛出错误。蟒蛇 - 项目不在列表中(但它是) - 复制列表
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-06 23:51:20
您是否有可能删除已删除的内容? – 2014-11-06 23:55:02
你可以'添加多肽'你*想保留*到一个新的列表?或者你必须删除它们?你可能需要小心以'list'作为输入参数,然后返回它,你听说过修改'in place'吗?你可以看到一些你不期望的行为。在代码中分隔不同位的代码中还有几行空白行看起来不错:P我仍然这样做。 – 2014-11-06 23:55:20