insertion_sort.py

#!/usr/bin/python3
# ===================================================================
#
# ===================================================================

def InsertionSort(lst):

    for idx in range(1,len(lst)):

        print(f'[idx: {idx}] {lst}')

        cur = lst[idx]                   # current element
        pos = idx

        while cur < lst[pos-1] and pos > 0:
            lst[pos] = lst[pos-1]
            pos = pos - 1

            print(f'         {lst}')

        lst[pos] = cur

        print(f'---------{lst}')

lst = [ 6,5,4,3,2,1 ]

InsertionSort(lst)

print(f'[final]  {lst}')