0
How to arrange the numbers in ascending order in python using only if else statement
2 Respostas
+ 5
May be this helps: set does sort numbers correctly but does not work in this way with characters:
print(set([1, 3, 0]))
print(set(['b', 'a', 'x']))
# output:
#{0, 1, 3}
#{'a', 'x', 'b'}
0
list=[7,4,6,6,3,10,7]
for i in range(len(list)-1):
for i in range(len(list)-1):
if (list[i]>list[i+1]):
list[i],list[i+1]=list[i+1],list[i]
# the for loops can be replaced by list.sort()
My program can arrange numbers even when some of them are equal and the duplicates will not be deleted.