Custom Sort Method In Python Is Not Sorting List Properly
I'm a student in a Computing class and we have to write a program which contains file handling and a sort. I've got the file handling done and I wrote out my sort (it's a simple so
Solution 1:
defsuper_simple_sort(my_list):
switched = Truewhile switched:
switched = Falsefor i inrange(len(my_list)-1):
if my_list[i] > my_list[i+1]:
my_list[i],my_list[i+1] = my_list[i+1],my_list[i]
switched = True
super_simple_sort(some_list)
print some_list
is a very simple sorting implementation ... that is equivelent to yours but takes advantage of some things to speed it up (we only need one for loop, and we only need to repeat as long as the list is out of order, also python doesnt require a temp var for swapping values)
since its changing the actual array values you actually dont even need to return
Post a Comment for "Custom Sort Method In Python Is Not Sorting List Properly"