1def selection(s):
2 for i in range(0,len(s)-1):
3 p=0
4 mini=s[-1]
5 for j in range(i,len(s)):
6 if s[j]<=mini:
7 mini=s[j]
8 p=j
9 s[i],s[p]=s[p],s[i]
10print(s)
11selection([2,3,4,2,1,1,1,2])
1def selection_sort(lst):
2 empty_lst = []
3 x = len(lst) - 1
4 while x>=0:
5 for i in range(len(lst)):
6 if lst[i] <= lst[0]:
7 lst[0],lst[i] = lst[i],lst[0]
8 # this part compares the number in first index and numbers after the first index.
9 g = lst.pop(0)
10 empty_lst.append(g)
11 x -= 1
12 return empty_lst
13
14print(selection_sort([2,3,4,2,1,1,1,2]))