+ 2

Sorting list without builtin functions

Hi i am learning python. Our mentor made homework: to sort this list [1, 2, 4, -5, 7, 9, 3, 2], in ascending order. Without using sort, min max. We studied for now Loops, List , if condition. What functions should i use? While ? In range?

21st Sep 2022, 4:17 PM
Petr Timofeev
Petr Timofeev - avatar
3 Answers
+ 1
You can use for loop (in range). Tips : use a for loop into an other for loop...
21st Sep 2022, 5:00 PM
Roland
Roland - avatar
0
(⌐■_■) Hope this link helps you https://www.sololearn.com/compiler-playground/c75as28IuUKW lst = [1, 2, 4, -5, 7, 9, 3, 2] for x in range(len(lst)): for y in range(len(lst)-1): if lst[y]>lst[y+1]: lst[y],lst[y+1] = lst[y+1],lst[y] x=0 print(lst)
21st Sep 2022, 6:28 PM
SoloProg
SoloProg - avatar
0
list=[1, 2, 4, -5, 7, 9, 3, 2] b=True while b: b=False for i in range(len(list)-1): if list[i]>list[i+1]: b=True list[i],list[i+1]=list[i+1],list[i] print(list)
22nd Sep 2022, 11:29 PM
ALI Moussa Kadjalla
ALI Moussa Kadjalla - avatar