Here’s a code for selection sort but it doesn’t print the sorted list. How can I show it?
badlist = input("Enter list: ")
def select(badlist):
l = list[:]
sorted = []
while len(l):
lowest == l[0]
for x in l:
if x < lowest:
lowest = x
sorted.append(lowest)
l.remove(lowest)
return sorted
select(badlist)
Use
print.If you are using Python 2.x
printis a keyword:In Python 3.x
printis a function and you must use parentheses:You also have at least two other errors:
badlistbut you never use it.==operator is equality comparison. You need=for assignment.Also your algorithm will be very slow, requiring O(n2) operations.