我写了这个程序:蟒蛇:IndexError:列表分配索引超出范围
l = []
N = int(input("enter the size of the list"))
if N < 50:
for i in range(N):
a = int(input("add a number to the list"))
l.append(a)
for i in range(N):
del l[min(l)]
print(l)
,当我运行它,他们说
Traceback (most recent call last):
File "<pyshell#5>", line 2, in <module>
del l[min(l)]
IndexError: list assignment index out of range
,请你有什么解决方案?
你怎么想恰恰在这一步'德尔L [分钟(L)]'怎么办?考虑列表'[10,20,30]'现在图像'德尔升的执行[分钟(L)]'。这将是'德尔升[10]',但没有在列表中第10元件,因而示出了错误 – ZdaR
假设l为[23,42,99]。然后'德尔升[分钟(升)]'相当于'德尔升[23]',它相当于“删除升的第24元素”。但我没有24个元素,它有三个元素。 – Kevin