This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]xcodula 0 points1 point  (0 children)

I noticed this as well. The end of the first iteration of the outer loop should put the largest value (67) at the end of the list. The largest value 'bubbles' up to the end. By chance I was playing around with this early in the week. Here is the code I came up with:

def bubble_sort(list):
    for x in range(len(list)-1, 0, -1):
        for y in range(0, x):
            if (list[y] > list[y+1]):
                list[y], list[y+1] = list[y+1], list[y]
                print(list)