sorting a list | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

sorting a list

hi, i wrote this code for sorting a list. i don't want to use sort method. would you help me to correct it? def sorting(mylist): for i in range(0,len(mylist)): newlist=[] temp=0 if mylist[i]>mylist[i+1]: temp = mylist[i] mylist[i]=mylist[i+1] mylist[i+1]=temp newlist.append(temp) return newlist

27th Sep 2018, 10:13 AM
Neda
1 Answer
+ 2
there are a lot of mistakes, i recomend reading this article about ths simplest sorting algorithm - bubble sort http://interactivepython.org/runestone/static/pythonds/SortSearch/TheBubbleSort.html
27th Sep 2018, 10:21 AM
__Nick
__Nick - avatar