Hello, I’m implementing the selection sort. my implementation passes the tests but I think mine isn’t exactly selection sort. can anyone help?
here’s my code:
def selection_sort(items):
items = items[:]
result = []
while len(items):
result.append(min(items))
items.remove(min(items))
return result
because instead of swapping, I’m just adding it to a new list and also, I’m using python built-in min instead doing a for loop to find the minimum thing there.
I see what you mean. It is close, like you’re breaking the list out into 2 lists, but there’s no still “swap”. I guess the tests are mainly checking that you output a sorted list, which you do.
Don’t worry about using min() I think that’s a good idea and it’s not forbidden by the instructions. Doing this in a loop is just extra legwork for no reason.
You’ve satisfied the instructions and the tests, so feel free to move on. I encourage you to re-write your program to do the swap though, I think that would be good practice and satisfying.
Good catch though, I’m going to open an Issue about this lab.
Thank you for helping make FCC better. Bugs can be reported as GitHub Issues. Whenever reporting a bug, please check first that there isn’t already an issue for it and provide as much detail as possible.