def selection_sort(lst): """ Sort lst in-place using selection sort """ for pos in range(len(lst)): # get the next smallest in lst[pos] # find the next smallest small = lst[pos] # smallest value seen so far smallpos = pos # position of small in lst for i in range(pos+1, len(lst)): # check each value, searching for one # that's smaller than the current smallest. if lst[i] < small: small = lst[i] smallpos = i # swap it into lst[pos] lst[pos], lst[smallpos] = lst[smallpos], lst[pos]