Last active
October 3, 2015 15:16
-
-
Save multivac61/60a7a625dba405ce8976 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def selection_sort(m, sort_by=(lambda a, b: a < b)): | |
def find_next(m): | |
next_elem = m[0] | |
for i in m: | |
if sort_by(i, next_elem): | |
next_elem = i | |
return next_elem | |
if len(m) <= 1: # if list less than one element return | |
return m | |
initial_list = list(m) # deepcopy of passed in list | |
sorted_list = [] | |
while initial_list: | |
next_min = find_next(initial_list) # find | |
sorted_list.append(next_min) | |
initial_list.remove(next_min) | |
return sorted_list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment