-1

I want to order a list of numbers. while I know that I can use insteas sort() and sorted(), could you please still help me see what is wrong with my code. Here is the first try:

def order_num(a_list):

list = []
for i in a_list:
    for j in a_list:
        if i > j:
            list.append(i)
            a_list.remove(i)
        elif i == j:
            list.append(i)
            a_list.remove(i)
        else:
            list.append(j)
            a_list.remove(j)
print(a_list)
the_list = [1, 2, 3, 4, 5]
order_num(the_list)

This gives me an unexpected result like just

[2,4]
Ben
  • 37
  • 5
  • don't `list` as variable name, that is the builin list method constructor name `list()` – azro May 07 '22 at 07:25

0 Answers0