If I have a list that changes in length each time, and I want to sort it from lowest to highest, how would I do it?
If I have: [-5, -23, 5, 0, 23, -6, 23, 67]
I want: [-23, -6, -5, 0, 5, 23, 23, 67]
I'll start with this:
data_list = [-5, -23, 5, 0, 23, -6, 23, 67] new_list = [] minimum = data_list[0] # arbitrary number in list for x in data_list: if x < minimum: minimum = value new_list.append(i)
BUT this only goes through once, and I get:
new_list = [-23]
This is where I am stuck.
How can I continue the cycle until len(new_list) = len(data_list)
(i.e. all numbers will not be in the new list) with everything sorted without using the built-in functions max, min, sort? I am not sure whether to create a new list.