```
def selectionsort(lst):
for x in range(len(lst)):
#find the smallest element in the list starting at x
sml = x #sml is the smallest element so far. we start at x
for y in range(x + 1, len(lst)): #go through the rest of the list
if lst[sml] > lst[y]: #if the smallest element so far is greater that the current element,
sml = y #mark that element as the smallest element
#swap element x with the smallest element
swap(lst, x, sml)
```

Advertisements