I have this Python code, is a recursive form of the Selection Sort Algorithm, but it doesn't work, can someone help me?
def selection(lista):
return selection_aux(lista,0,len(lista))
def selection_aux(lista,i,n):
if i == n or lista[0]==None:
return lista
else:
num_menor = menor_f(lista,i,n,i)
temporal = lista[i]
lista[i] = num_menor
print(num_menor)
lista[num_menor] = temporal
return selection_aux(lista,i+1,n)
def menor_f(lista,j,n,menor):
if j == n:
return menor
if lista[j] < lista[menor]:
menor = j
return menor_f(lista,j+1,n,menor)
Test:
>>> selection([1,2,3])
Output
lista[num_menor] = temporal
TypeError: list indices must be integers, not NoneType