Skip to content

Instantly share code, notes, and snippets.

@srakrn
Created December 8, 2017 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srakrn/82fba61c7538b019b0d125e9e700f9a0 to your computer and use it in GitHub Desktop.
Save srakrn/82fba61c7538b019b0d125e9e700f9a0 to your computer and use it in GitHub Desktop.
def selection_sort(l):
for i in range(len(l)-1):
minimum = l[i]
minimum_pos = i
for j in range(i+1, len(l)):
if l[j] < minimum:
minimum = l[j]
minimum_pos = j
l[i], l[minimum_pos] = l[minimum_pos], l[i]
return l
import random
l = [random.randint(1, 20) for _ in range(20)]
print(selection_sort(l))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment