python输入数组排序_python 根据规则进行数组排序

我也不知道怎么解释。。。cmp是提供了比较的规则,s通过调用cmp指定的函数来比较两个成员

这是sort函数在帮助文档,你看看吧

s.sort([cmp[, key[, reverse]]])

The sort() method takes optional arguments for controlling the

comparisons.

cmp specifies a custom comparison function of two arguments (list

items) which should return a negative, zero or positive number depending on

whether the first argument is considered smaller than, equal to, or larger than

the second argument: cmp=lambda x,y: cmp(x.lower(), y.lower()). The

default value is None.

key specifies a function of one argument that is used to extract a

comparison key from each list element: key=str.lower. The default value is None.

reverse is a boolean value. If set to True, then the list

elements are sorted as if each comparison were reversed.

In general, the key and reverse conversion processes are

much faster than specifying an equivalent cmp function. This is because

cmp is called multiple times for each list element while key

and reverse touch each element only once.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值