Skip to content

Commit 5e94cab

Browse files
authored
Merge pull request #4 from kgashok/master
Update recipe-576917.py
2 parents daa8afb + c3f4ec4 commit 5e94cab

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

recipes/Python/576917_Functional_selection_sort/recipe-576917.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,9 @@
1515
test_list = [ 5, 1, 7, 0, -3, -10, 10, -6, 1, 0, 2, 4, -2, 6, 5, 8, 2]
1616
print test_list
1717
print selection_sort(test_list)
18+
19+
# Recursive version
20+
def select_sort_r(L):
21+
if not L: return [] # terminal case
22+
v, idx = min((v, i) for i, v in enumerate(L)) # select the smallest
23+
return [v] + select_sort_r(L[:idx] + L[idx+1:]) # recursively call on the remainder

0 commit comments

Comments
 (0)