小编use*_*772的帖子

比较列表中的元素

我刚开始学习Python ...我正在编写一个简单的程序,它将采用整数并保留未排序和排序的列表.我遇到排序列表部分的问题...我在比较列表中元素的值时遇到错误.我得到错误的地方是以下行:"if sortedList [sortcount]> sortedList [count]:".我得到"TypeError:unorderable types:list()> int()".

这是代码的一部分......我不确定是什么问题.

numberList = []
sortedList = []
count = 0
sum = 0

....(skip)....

sortcount = 0
sortedList += [ int(userInput) ]
while sortcount < count:
    if sortedList[sortcount] > sortedList[count]:
        sortedList[count] = sortedList[sortcount]
        sortedList[sortcount] = [ int(userInput) ]  
    sortcount+=1
Run Code Online (Sandbox Code Playgroud)

python list python-3.x

2
推荐指数
1
解决办法
266
查看次数

标签 统计

list ×1

python ×1

python-3.x ×1