为了账号安全,请及时绑定邮箱和手机立即绑定

嵌套列表迭代输入特定值会报错:ValueError: list.remove(x): x not in list

嵌套列表迭代输入特定值会报错:ValueError: list.remove(x): x not in list

#这段代码输入以下值会报错,输入其他值都不报错,一直查不出为什么,请大神们帮忙看下,谢谢。# 5# Prashant# 52.22# Kush# 52.223# Kant# 52.222# Kanti# 52.2222# Harshit# 52.22222M = []for _ in range(int(raw_input())):    name = raw_input()    score = float(raw_input())    L = []    L.append(name)    L.append(score)    M.append(L)if len(M) < 2:    print '2 names must be given at least.'if len(M) > 5:    print 'The number of names can not exceed 5'N = []for x in M:    for y in M:        if x[1] > y[1] and x not in N:            N.append(x)for sec in N:    for bigger in N:        if sec[1] < bigger[1]:            N.remove(bigger)        if sec[1] > bigger[1]:            N.remove(sec)N.sort()for result in N:    print result[0]
查看完整描述

1 回答

?
你那矫情的小眼神

TA贡献7条经验 获得超0个赞

L=[]每次循环都会清零啊

查看完整回答
反对 回复 2017-06-27
  • 1 回答
  • 0 关注
  • 1365 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信