Zhong__python中快速排序示例

# 定义一个函数test()

def test(ls):
    if len(ls) <= 1:return ls
    return test([lt for lt in ls[1:] if lt < ls[0]]) + ls[0:1] + test([gt for gt in ls[1:] if gt >= ls[0]])

a = [13,14,0, -1,-2 ,2,5]

print(test(a))
注意点 ls应为列表格式  ls[0:1]为列表格式  才可

猜你喜欢

转载自blog.csdn.net/anyedianxia/article/details/80932850