python list列表sort、sorted、reverse排序
2024-09-04 13:12:27
列表排序:sort是修改原列表,sorted提供原列表的一个有序副本
li=[2,1,4,5,0]
li.sort() #默认从小到大
print li
结果:[0, 1, 2, 4, 5] li=[2,1,4,5,0]
li.sort(reverse=True) #从大小到
print li
结果:[5, 4, 2, 1, 0] li=[2,1,4,5,0]
new = sorted(li)
print new,li
结果:[0, 1, 2, 4, 5] [2, 1, 4, 5, 0] li=[2,1,4,5,0]
li.reverse() #反转列表
print li
结果:[0, 5, 4, 1, 2]
最新文章
- android中实现跑马灯效果以及AutoCompleteTestView与MultiAutoCompleteTextView的学习
- 超链接的那些事(三): 属性target
- HDU 1248 寒冰王座(全然背包:入门题)
- php 抓取天气情况 www.weather.com.cn
- babel7-按需加载polyfill
- BInsertSort
- P1433 吃奶酪(搜索DFS+记忆化)
- Angular、React.js 和Node.js到底选谁?
- Android NDK开发调试
- Java排序之升序与降序
- 2018.10.19 NOIP模拟 加密(模拟)
- mysql安装(rpm)
- 同时安装2个版本的python
- WCF 之部署(2010版本之上)
- 20135208 JAVA第三次实验
- spring源码解析--事务篇(前篇)
- iView--3
- Java 基于javaMail的邮件发送(支持附件)
- SpringAOP源码分析总结
- Leetcode 557. 反转字符串中的单词 III
热门文章
- SQLite集成与用法
- 【BZOJ4373】算术天才⑨与等差数列 线段树+set
- Python中高层次的数据结构,动态类型和动态绑定,使得它非常适合于快速应用开发,也适合于作为胶水语言连接已有的软件部件。
- Failed to load http://wantTOgo.com/get_sts_token/: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://fromHere.com' is therefore not allowed access.
- 记录Elasticsearch的一次坑
- 【24题】P2766最长不下降子序列问题
- 移动App该怎样保存用户password
- Java中Iterator的fast-fail分析
- mongoDB多级子文档查询
- eclipse显示adb is down错误,无法真机调试