Python 排序函数sorted
来源:互联网 发布:周生生网络旗舰店 编辑:程序博客网 时间:2024/06/06 02:01
Python 排序函数sorted
函数原型sorted(iterable, key=None, reverse=False)
* iterable 是待排序的数据结构
* key 元素评价函数 用来评价元素大小
* reverse 是否倒序
* 返回值是排好序的数据结构,不改变源数据结构
简单列表结构
a = [9, 8, 6, 3, 2, 1]result = sorted(a,reverse=True)print(result) #[9, 8, 6, 3, 2, 1]
复杂列表结构
a = [(1,9),(2,8),(3,7),(4,6),(5,0)]result = sorted(a,key=lambda x:x[0])#评价函数返回元素第一个值,元素大小按第一个值算print(result)#[(1, 9), (2, 8), (3, 7), (4, 6), (5, 0)]
0 0
- Python 排序函数sorted
- python的sorted 函数、python列表排序
- python内置函数sorted排序用法
- python内置函数sorted排序用法
- python内置函数sorted排序用法
- python排序函数sort()与sorted()区别
- python字典排序及sorted函数
- python的排序函数sort,sorted
- python排序函数sort()、sorted()、argsort()
- Python学习(五)—sorted排序函数
- python排序函数sort()与sorted()区别
- Python中的排序函数argsort,sort,sorted
- Python的排序函数Sort,Sorted
- Python排序函数sort()和sorted()详解
- python排序sorted()与operator.itemgetter()函数
- Python的排序方法:list.sort函数和sorted函数
- python dict sorted 排序
- python dict sorted 排序
- Linux基础学习笔记之root用户与普通用户
- (最小堆)哈夫曼树 ->求结点值与权值积的和
- 看懂论文的机器学习基本知识(三)--假正例、假负例、ROC曲线
- 【linux】安装yum源或者yum安装软件时候报错
- NVR、DVR的区别
- Python 排序函数sorted
- zookeeper集群扩容/下线节点实践
- 看懂论文的机器学习基本知识(四)--bootstrap
- [POJ] 2251 Dungeon Master
- CSS(2)css文件样式
- JAVA环境变量JAVA_HOME、CLASSPATH、PATH设置详解
- NSArray & NSMutableArray 常用方法
- char * 和 char []的区别
- RxJS —— 异步数据流利器