Skip to content

Instantly share code, notes, and snippets.

@xiaotangyuan
Created July 4, 2016 03:19
Show Gist options
  • Save xiaotangyuan/2480514868b3e9a332cb55af9f654523 to your computer and use it in GitHub Desktop.
Save xiaotangyuan/2480514868b3e9a332cb55af9f654523 to your computer and use it in GitHub Desktop.
选择排序
def selectorder(thelist):
for index,num in enumerate(thelist):
minnum = num
minnum_index = index
for index2,num2 in enumerate(thelist[index+1:]):
if num2 < minnum:
minnum = num2
minnum_index = index + index2 + 1
thelist[index] = minnum
thelist[minnum_index] = num
return thelist
if __name__ == '__main__':
thelist = [9,1,4,2,9,5,3,1,98,46]
res = selectorder(thelist)
print res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment