Skip to content

Instantly share code, notes, and snippets.

@adabson
Created February 12, 2012 22:31
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 adabson/1811236 to your computer and use it in GitHub Desktop.
Save adabson/1811236 to your computer and use it in GitHub Desktop.
Khan sorting python example
#sorting function
#Andrew Dabson onitz.net
def mysort(list):
for j in range(len(list)): #iterate through the list
b=j #let b be the index of the smallest value
for i in range(j,len(list)): #iterate through the last portion
if(list[i]<list[b]): #..and find the next smallest value
b=i
c=list[j] #swap the ith value with the smallest
list[j]=list[b]
list[b]=c
return list #and return the result
a=[7,1,3,5,2,8]
print(mysort(a))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment