0
点赞
收藏
分享

微信扫一扫

2个for循环实现源数据重组排序

天使魔鬼 2023-12-11 阅读 34

有一个list,从上一个def函数中得到数据持续写入数组,需要按数值大小自动重新排序?


实现代码

def renew_(listx):
    for i in range(len(listx)-1):
        for j in range(i+1,len(listx)-1):
            if listx[i] > listx[j]:
                listx[i],listx[j]=listx[j],listx[i]
                
    return listx
listx = [20, 42, 37, 59, 31, 11,68,95]
print(renew_(listx))

计算结果

2个for循环实现源数据重组排序_for


举报

相关推荐

0 条评论