# Sorts the list in ascending order by selection sort def selectionSort(myList): #outer loop keeps track of the dividing line between #the sorted and unsorted part of myList for lastUnsortedIndex in range(len(myList)-1, 0, -1): # search of the largest item in the unsorted # part of myList, i.e., myList[0 .. lastUnsortedIndex] # Assume the first item is the largest maxIndex = 0 # Correct the assumption by looking for a larger item for testIndex in range(1, lastUnsortedIndex+1): if myList[testIndex] > myList[maxIndex]: maxIndex = testIndex # Now, maxIndex is the location of the largest # item in the unsorted part, so "swap" it with # the last unsorted item to extend the sorted part temp = myList[maxIndex] myList[maxIndex] = myList[lastUnsortedIndex] myList[lastUnsortedIndex] = temp