def choose_sort(raw_list):
"""对列表选择排序"""
# 循环次数控制n-1
for times in range(len(raw_list)-1):
# 循环开始先假设第一个元素为最小值
min_value = raw_list[times]
# 遍历列表中的无序部分 如果元素小于min_value 就给min_value重新赋值
if raw_list[times] < min_value:
min_value = raw_list[times]
# 最后将min_value 放到下标为times的位置上
raw_list[times] = min_value
print(raw_list)
if __name__ == ‘__main__‘:
alist = [3, 1, 4, 5, 2, 1, 7]
choose_sort(alist)
---------------------------------
[1, 1, 2, 3, 4, 5, 7]