pyhon sorted,sort,cmp

关于sorted排序:
python2

  1. 可以根据 cmp,或者key= 一个函数 用于指定 哪个字符
    http://www.runoob.com/python/python-func-sorted.html
    http://www.runoob.com/python/func-number-cmp.html (cmp)

python3 ,没有了 cmp关键字,:
https://www.polarxiong.com/archives/Python3-找回sort-中消失的cmp参数.html

sort 官方文档:
https://docs.python.org/3.6/howto/sorting.html#sortinghowto
可以关注下operator模块,结合key关键字


关于 sort
list中有的属性,也有key


有一个奇怪的现象:
本身repr是返回字符串的:

但如果在类中定义了__repr__, 用元组包含两个以上元素,repr返回的并不再是字符串了:……还没想清楚原因
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/xnmc2014/article/details/86361416
今日推荐