这是一个程序,它应该打印一个长度递减的字符串。但是这段代码正在反向打印给定的字符串。你知道我在这段代码中遗漏了什么吗?你知道吗
def listsorter(lst):
lst=lst.split(" ")
lstsize=list("a"*len(lst))
lstindex=lstsize
looper=len(lst)
other=lst
for i in range(looper):
lstsize[i]=len(lst[i])
lstindex[i]=lst.index(lst[i])
while len(lstsize)>1:
temp=max(lstsize)
temp1=lstsize.index(temp)
print(other[temp1])
lstsize.pop(temp1)
else:
print(lst[0])
user_input=input("Enter anything\n")
listsorter(user_input)
你想要这样的东西吗:
要做到这一点而不使用内置的
sorted
函数,您可以构建自己的排序算法。气泡排序是最容易理解的。你知道吗编辑:我猜詹姆斯写的是你想要的?你知道吗
相关问题 更多 >
编程相关推荐