i want to create a function that does the same as the build-in function .sort(), but it is more difficult than i think.
my function is as below:
-------------------------------------
-------------------------------------
i tried sort([32,25,31,3,6,4, 0]), but the output only had sorted the some of the numbers. it gave [25, 31, 3, 6, 4, 0, 32] instead of giving me a list of ascending numbers.
where went wrong with my function?
my function is as below:
-------------------------------------
Code:
def sort(l):
"""sort a list of #s"""
for i in range(len(l)-1):
if l[i] > l[i+1]:
l[i+1], l[i] = l[i], l[i+1]
print l
i tried sort([32,25,31,3,6,4, 0]), but the output only had sorted the some of the numbers. it gave [25, 31, 3, 6, 4, 0, 32] instead of giving me a list of ascending numbers.
where went wrong with my function?
Comment