list = [37,20,3,2,66,5]
oglist = []
a = list[0]
while len(list) > 2:
for i in list:
if a <= i:
continue
else :
a = i
continue
oglist.append(a)
list.pop(list.index(a))
print(oglist)
randomList = [37,20,3,2,66,5]
sortedList = []
while len(randomList) > 0:
a = randomList[0]
for i in randomList:
if a <= i:
continue
else :
a = i
continue
sortedList.append(a)
randomList.pop(randomList.index(a))
print(sortedList)
如注释中所述,您正在重写类名
list
。 我看到的另一个问题是a
不是每次遍历循环时都重置的:在第一次遍历之后,a
的值是66,并且一直保持66直到结束。你知道吗我将
a = randomList[0]
移动到while循环中,这样a的值总是列表中某个元素的值。我还将条件更改为
len(randomList)>0
,以便继续排序,直到参数列表为空如果我了解你的主要问题,这是一个简单的解决办法。你知道吗
相关问题 更多 >
编程相关推荐