The code below is not iterating through the list and sorting the list. How should I tweak it just enough to make it work while still looking a little the same? I've tried multiple ways to make it work to no avail. Oh and, I'm aware of the Selection sorting shortcut, the sort() function, but I want to learn the long way as well in how to code functions, programs and processes. Thanks!
def sortList(L,n):
minValue = L[0]
L2 = []
idx = 0
counter = 0
while (counter < n):
v = L[counter]
if v < minValue:
minValue = v
idx = counter
L2.append(minValue)
del L[idx]
n-=1
counter += 1
return L2
L = [34, -1, 0, 89, 21, -40, 7]
n = len(L)
print(sortList(L, n))