List exercise
2024-08-26 21:23:53
The slice operator can take a third argument that determines the step size, so t[::2] creates a list that contains every other element from t. If the step size is negative, it goes through the list backward, so t[::-1] creates a list of all the elements in t in reverse order. Use this idiom to write a one-line version of is_palindrome
Write a function called is sorted that takes a list as a parameter and returns True if the list is sorted in ascending order and False otherwise. You can assume (as a precondition) that the elements of the list can be compared with the comparison operators <, >, etc.
For example, is sorted([1,2,2]) should return True and is sorted([’b’,’a’])
should return False
.
from Thinking in Python
最新文章
- 【Android】 修复ijkPlayer进行m3u8 hls流播放时seek进度条拖动不准确的问题
- 相机位姿估计0:基本原理之如何解PNP问题
- UML学习笔记1
- jenkins2 Jenkinsfile和load
- 第二章 OO大原则
- 序列化LinkedHashMap,有序输出Json字符串
- JAVA EE 第一阶段项目问题
- 联系电话正则表达式(jquery表单验证)
- Photoshop:去掉投影
- eclipse mingw cpp开发环境
- VI命令删除文件所有内容
- Qt-获取网络接口信息的综合示例
- RedHat7安装Sublime Text 3
- PC-lint 简明教程
- Wowza流媒体Live直播和VOD点播配置实战
- 洛谷P3164 [CQOI2014]和谐矩阵
- 集合源码分析[2]-AbstractList 源码分析
- JS定义一个立即执行的可重用函数
- 普通for循环和增强for循环的区别
- mybatis由浅入深day01_5.3 Mapper动态代理方法