Answers for "how to sort without using sort in python"

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

Code answers related to "how to sort without using sort in python"

Python Answers by Framework

Browse Popular Code Answers by Language