Answers for "sorting a list in python without sort"

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
Posted by: Guest on November-18-2020
0

python sorting array without inbuilt sort

data_list = [-5, -23, 5, 0, 23, -6, 23, 67]
new_list = []

while data_list:
    minimum = data_list[0]  # arbitrary number in list 
    for x in data_list: 
        if x < minimum:
            minimum = x
    new_list.append(minimum)
    data_list.remove(minimum)    

print new_list
Posted by: Guest on September-06-2021
-1

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)
Posted by: Guest on February-05-2021

Code answers related to "sorting a list in python without sort"

Python Answers by Framework

Browse Popular Code Answers by Language