标签:span index pytho sort 实现 sel ret for append
def findsmallest(arr):
smallest=arr[0]
smallest_index=0
for i in range(1,len(arr)):
#smallest_index+=1
if arr[i]<=smallest:
smallest=arr[i]
smallest_index=i
return smallest_index
def selectionsort(arr):
l=[]
for i in range(len(arr)):
smallest=findsmallest(arr)
l.append(arr.pop(smallest))
return l
a=[7,4,8,2,9]
print(selectionsort(a))
pop()用法括号中是index
标签:span index pytho sort 实现 sel ret for append
原文地址:https://www.cnblogs.com/masterhu/p/9614859.html