Skip to content

Instantly share code, notes, and snippets.

@edumelzer
Created May 27, 2013 15:41
Show Gist options
  • Save edumelzer/788540cc5e9b08e2e52f to your computer and use it in GitHub Desktop.
Save edumelzer/788540cc5e9b08e2e52f to your computer and use it in GitHub Desktop.
select_on_sort python (working)
print 'Digite os valores a serem ordenados separados por virgula:'
valores = [2,5,3,9,8]
def selection_sort(list):
l=list[:] # create a copy of the list
sorted=[] # this new list will hold the results
while len(l): # while there are elements to sort...
lowest=l[0] # create a variable to identify lowest
for x in l: # and check every item in the list...
if x<lowest: # to see if it might be lower.
lowest=x
sorted.append(lowest) # add the lowest one to the new list
l.remove(lowest) # and delete it from the old one
return sorted
print selection_sort(valores)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment