Python - sorted 排序

来源:互联网 发布:营销软件广告 编辑:程序博客网 时间:2024/06/08 20:31
# -*- coding=utf-8 -*-# sorted()函数 list排序# 如:[5, 9, 12, 21, 36]# s = sorted([36, 5, 12, 9, 21])# print s# sorted()函数 自定义排序l = [36, 5, 12, 9, 21]# 自定义排序方法 repdef rep(x,y):    if x > y:        return -1    if x < y:        return 1    return 0# sorted(需排序变量 ,自定义排序函数名)s = sorted(l , rep)print(s)

0 0