SPOILERS - this post contains a potential solution for the Implement the Selection Sort Algorithm exercise in the Python curriculum.
I found a way to implement selection sort that is different from what I saw in the forums after completing it, and doesn’t match the common solutions you can find in keyword searches online. I wondered if I could get some feedback. Is this a viable solution? Is it efficient enough to be worth using?
def selection_sort(numbers):
index = 0
length = len(numbers)
while index < length:
small = min(numbers[index:length])
index_small = numbers.index(small, index)
if index == index_small:
index += 1
else:
numbers[index], numbers[index_small] = numbers[index_small], numbers[index]
index += 1
return numbers
Thank you!