I have been searching for various alternatives but I am not able to sort the array from least to greatest without sort(). How can I detect?
serie = [4,3,2,1,6,8,7]
for i in serie:
if i > 0:
i = i - 1
print(i)
I have been searching for various alternatives but I am not able to sort the array from least to greatest without sort(). How can I detect?
serie = [4,3,2,1,6,8,7]
for i in serie:
if i > 0:
i = i - 1
print(i)
Good day,
You could loop through the list with 2 loops
for
one to loop through all the values and one to loop from the next position of the current iteration to the end, compare the numbers and if larger swap themThis returns:
Another option would be to create a new list, compare each value of the series with the first value, in case of finding a smaller one, obtain it, if there is no smaller one then the smaller one would be the first element, remove that element from the original series and add it with
append
to the new list. At the end of the original list there will be 0 elements and in the new list you will have all the elements sortedThis returns: