python的sorted用法
来源:互联网 发布:python 绝技 目录 编辑:程序博客网 时间:2024/05/16 01:35
#1
a = [7,8,4,6,2]
a = [7,8,4,6,2]
print(sorted(a))
结果[2, 4, 6, 7, 8]
#2
b = [('b',2),('a',1),('c',0)]
结果
[('a', 1), ('b', 2), ('c', 0)]
#3
c = sorted(b,key = lambda x:x[0])
print(c)
d = sorted(b,key = lambda x:x[1])
print(d)
结果
[('a', 1), ('b', 2), ('c', 0)]
[('c', 0), ('a', 1), ('b', 2)]
#下面的python3可能不适用
#4我们用x表示列表里第一个元素,y表示列表里第二个元素,
#x[1]表示第一个元组的第二个元素,
#同理y[1]也是,而cmp()就是比较函数,也就是说,比较x[1]和y[1]的大小
e = sorted(b,cmp = lambda x,y:cmp(x[1],y[1]))
print(e)
0 0
- python的sorted用法
- Python sorted()的用法
- Python 中 sorted 的用法
- Python: sort,sorted,OrderedDict的用法
- Python中sorted()方法的用法
- Python中sorted()方法的用法
- Python中sorted()方法的用法
- Python: sort,sorted,OrderedDict的用法
- Python中sorted()方法的用法
- Python中sorted()方法的用法
- Python中sorted函数的用法
- Python中sorted()方法的用法
- Python中sorted()方法的用法
- Python中sorted()方法的用法
- Python中sorted函数的用法
- Python中sorted函数的用法
- Python中sorted函数的用法
- Python中sorted函数的用法
- Python if 语句
- bzoj 2762 树状数组
- 《APUE》读书笔记—第八章进程控制
- TP-GAN 让图像生成再获突破,根据单一侧脸生成正面逼真人脸
- Python selenium 三种等待方式详解
- python的sorted用法
- 微信小程序的简单登录
- [LeetCode]122. Best Time to Buy and Sell Stock II
- 机器学习13-支持向量机大边界的直观理解
- android native层的opengltest程序学习例子
- jsp的九大内置对象和四大作用域
- Node.js Buffer(缓冲区)
- 斐波那契博弈
- 重载,覆盖,隐藏