python sort() sorted()
来源:互联网 发布:centos 编译安装git 编辑:程序博客网 时间:2024/05/17 03:30
list.sort() 不会返回对象,会改变原有的list ,默认地按升序排列,sort()只适应于列表
L =[34,22,56,18,90,30,21]print(L.sort())print(L)输出None[18, 21, 22, 30, 34, 56, 90]sort()函数原型:
L.sort(key=None, reverse=False)
reverse : 是否颠倒排列顺序,默认False
------------------------------------------------------------------------------------------------------------------------
sorted() 适应可迭代的对象 返回副本,原始输入不变
sorted(iterable,key=None, reverse=False)
iterable:可迭代的对象
key:排序需要比较的值
reverse :是否颠倒排列顺序,默认False
根据成绩来排名:
L =[("Joe","Math990112",89),("Mike","CS991301",100),("Mary","EE990830",95)]L1= sorted(L,key=lambda score:score[2])print(L)print(L1)输出:[('Joe', 'Math990112', 89), ('Mike', 'CS991301', 100), ('Mary', 'EE990830', 95)][('Joe', 'Math990112', 89), ('Mary', 'EE990830', 95), ('Mike', 'CS991301', 100)]
阅读全文
0 0
- python sorted和sort
- python--sort,sorted,argsort
- Python sort sorted 详解
- python sort and sorted
- Python sort与sorted
- Python sort and sorted
- Python sort and sorted
- Python sort sorted OrderDict
- python sort() sorted()
- python之sort(),sorted()
- Python sort sorted函数详解
- python的排序 sort sorted
- Python sort sorted函数详解
- Python sort sorted函数详解
- Python之 sort和sorted
- Python sort sorted函数详解
- python有关sorted和sort
- python sort / sorted 和 argsort()
- Zookeeper注册中心的搭建
- Java实现插入排序
- [JSOI2009]球队收益
- 几种刷新
- C++三大类IO概述
- python sort() sorted()
- SpringCloud微服务系列(2): 创建一个基于Springboot的RESTFul服务
- PAT 1013. Battle Over Cities (25)
- 向量算子(梯度、散度、旋度)与拉普拉斯算符的公式与定义整理
- ZOJ2042
- 面试--数据结构(5)(树)
- 面试题:插入排序
- 多级反向代理下,Java获取请求客户端的真实IP地址多中方法整合
- 经典Aop