deffind_two_smallest(L):'''Return a tuple of the indices of the two smallest values in list L'''if L[0] < L[1]:
min1,min2 = 0,1else:
min1,min2 = 1,0for n in range(2,len(L)):
if L[n] < L[min1]:
min2 = min1
min1 = n
elif L[n] < L[min2]:
min2 = n
return (min1,min2)
deflinear_search(L,v):'''Return the index of the first occurrence of v in list L, or return len
if v is not in L'''for i in range(len(L)):
if L[i] == v:
return i
return len(L)
defselection_sort(L):'''Reorder the values in L from smallest to largest.'''
i = 0while i != len(L):
smallest = find_min(L, i)
L[i],L[smallest] = L[smallest],L[i]
i += 1deffind_min(L,b):'''Return the index of the smallest value in L[b:].'''
smallest = b # The index of the smallest so far.
i = b + 1while i != len(L):
if L[i] < L[smallest]:
smallest = i
i += 1return smallest
definsertion_sort(L):'''Reorder the values in L from smallest to largest.'''
i = 0while i != len(L):
insert(L, i)
i += 1definsert(L, b):'''Insert L[b] where it belongs in L[0:b+1];
L[0:b-1] must already be sorted'''
i = b
while i != 0and L[i-1] > L[b]:
i -= 1
value = L[b]
del L[b]
L.insert(i, value)