sort list of numbers python without function code example
Example 1: order a list without sort
n = int(input("Elementos da lista = "))
lista = []
for i in range(n):
x = int(input("Valor (0 a 9) = "))
if (i == 0) or (x > lista[- 1]):
lista.append(x)
else:
pos = 0
while (pos < len(lista)):
if x <= lista[pos]:
lista.insert(pos , x)
break
pos = pos + 1
Example 2: sorting numbers in python without sort function
number=[1,5,6,9,0]
for i in range(len(number)):
for j in range(i+1,len(number)):
if number[i]<number[j]:
number[i],number[j]=number[j],number[i]
print(number)