# Insertion Sort that sorts a list in ascending order def insertionSort(myList): for firstUnsortedIndex in range(1, len(myList)): # copy the first unsorted element temp = myList[firstUnsortedIndex] # scan the sorted part from right to left looking # for the correct spot to insert the first unsorted element testIndex = firstUnsortedIndex - 1 while testIndex >= 0 and temp < myList[testIndex]: # slide the element to the right to make room for the # inserted element myList[testIndex+1] = myList[testIndex] testIndex = testIndex - 1 # after finding the correct spot insert the element myList[testIndex + 1] = temp