Posted on:

30 Mar 2023

0

Simpler solution to insertion sort

Here is a simpler solution for this sorting problem that I find more easy to read:

def insertion_sort(my_list):
    for i in range(1,len(my_list)):
        j = i
        while my_list[j] < my_list[j - 1] and j > 0:
            my_list[j - 1], my_list[j] = my_list[j], my_list[j - 1]
            j -= 1
0 answers ( 0 marked as helpful)

Submit an answer