# 定义一个函数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]为列表格式  才可

Author:Zhong

关注微信公众号:更多

Zhong__python中快速排序示例

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-06
  • 2021-11-24
  • 2021-12-09
  • 2021-11-19
  • 2021-08-21
猜你喜欢
  • 2021-05-30
  • 2021-09-24
  • 2022-12-23
  • 2022-12-23
  • 2021-08-02
  • 2022-12-23
相关资源
相似解决方案