1.直接对列表中的值进行操作
#找出列表中的最小值
def FindSmallest(F_list):
smallest=F_list[0]
for i in F_list:
if i<smallest:
print("zzx")
smallest=i
return smallest
#对列表进行选择排序
def xuanze(F_list):
new_list=[]
while F_list:
smallest=FindSmallest(F_list)
new_list.append(smallest)
F_list.remove(smallest)
return new_list
2.对列表中的索引进行操作
#取出列表中最小值的索引
def FindSmallest(F_list):
smallest=F_list[0]
smallest_index=0
for i in range(1,len(F_list)):
if F_list[i]<smallest:
smallest=F_list[i]
smallest_index=i
return smallest_index
#对列表进行选择排序
def xuanze(F_list):
new_list=[]
while F_list:
smallest_index=FindSmallest(F_list)
new_list.append(F_list[smallest_index])
F_list.pop(smallest_index)
return new_list
test_list=[4,8,2,-1,9,3,2,-8,3,7]
print(xuanze(test_list))