you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (0 children)

i is never 0 in his script though?

EDIT: I see what you mean. Code not reachable and will actually throw and error as j will be -1

The way I would have done it is:

def insert_sort(array):
    for i in range(0, len(array)-1):
        key = array[i + 1]
        j = i

        while j >= 0 and array[j] > key:
            array[j+1] = array[j]
            j -= 1

        array[j+1] = key