我最近正在自学python,我有解决方案,但我只想知道为什么L.appendix在这里有错误。
Given a list of number i.e. [1,2,3,-5,7,9,3,2],
make another list that contains all the items sorted from min to max
L=[1,2,4,-5,7,9,3,2]
M=[]
minv=L[0]
while not(len(L)==0):
for i in L:
if i<=minv:
minv=i
M.append(minv)
L.remove(minv)
list.remove(x):x不在列表中
发布于 2022-04-15 16:38:56
L.sort()将对列表进行排序,这可能有效,但与您的指示不同。如果您希望在保持L不变的情况下按正确顺序排列另一个列表,请使用内置排序()函数:
M = sorted(L)
https://stackoverflow.com/questions/71886414
复制相似问题