I just started learning Python… I am writing a simple program that will take in integers and keep an unsorted and sorted list. I’m having a problem with the sorted list part…
I’m getting an error when comparing the values of elements within the list. Where I get the error is the following line: “if sortedList[sortcount] > sortedList[count]:”. I get “TypeError: unorderable types: list() > int()”.
Here is part of the code… I’m not sure what is wrong.
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
where you do:
you should do:
otherwise you will add a list on that position and give the error you told.
BTW, on the first line before the while loop is better to write