def list_sort(lt,reverse = False): n = len(lt) for i in range(n-1): for j in range(i+1,n): if lt[i] > lt[j]: lt[i],lt[j] = lt[j],lt[i] lt = [1,3,5,7,9,2,4,6,8] list_sort(lt,reverse=False) print(lt)
#使用函数完成列表的排序
最新推荐文章于 2024-03-11 13:35:27 发布
def list_sort(lt,reverse = False): n = len(lt) for i in range(n-1): for j in range(i+1,n): if lt[i] > lt[j]: lt[i],lt[j] = lt[j],lt[i] lt = [1,3,5,7,9,2,4,6,8] list_sort(lt,reverse=False) print(lt)