0

How to arrange the numbers in ascending order in python using only if else statement

20th Aug 2019, 1:37 PM
Amritesh Gupta
Amritesh Gupta - avatar
7 Respuestas
+ 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'}
20th Aug 2019, 3:26 PM
Lothar
Lothar - avatar
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.
20th Aug 2019, 2:03 PM
Ketchup🍅
Ketchup🍅 - avatar