def bubble_sort(lista):
elementos = len(lista)-1
ordenado = False
while not ordenado:
ordenado = True
for i in range(elementos):
if lista[i] > lista[i+1]:
lista[i], lista[i+1] = lista[i+1],lista[i]
ordenado = False
print(lista)
return lista
Print this way bubble_sort ([5, 1, 4, 2])
[1, 5, 4, 2]
[1, 4, 5, 2]
[1, 4, 2, 5]
[1, 2, 4, 5]
should return [1, 2, 4, 5]
It's printing bubble_sort ([5, 1, 4, 2])
[1, 4, 2, 5]
[1, 2, 4, 5]
[1, 2, 4, 5]
[1, 2, 4, 5]