python列表的数字比大小

python列表的数字比大小,列表以从小到大的顺序排列

lt = [9, 4, 7, 8, 5, 6]


def list_sort(lt, key=None, reverse=False):
    for i in range(len(lt) - 1):
        for j in range(len(lt) - 1 - i):
            if lt[j] > lt[j + 1]:
                lt[j], lt[j + 1] = lt[j + 1], lt[j]
    return lt


print(list_sort(lt))

猜你喜欢

转载自blog.csdn.net/weixin_42185136/article/details/88389490