Insert Sort

def insertsort(lst):
    for x in range(len(lst)): #for each element
        for y in range(x, 0, -1): #go back through the sorted section of the list
            if lst[y - 1] > lst[y]: #if the y is greater than the previous
                swap(lst, y-1, y) #swap the two
Advertisements