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

最新文章

  1. 【Android】 修复ijkPlayer进行m3u8 hls流播放时seek进度条拖动不准确的问题
  2. 相机位姿估计0:基本原理之如何解PNP问题
  3. UML学习笔记1
  4. jenkins2 Jenkinsfile和load
  5. 第二章 OO大原则
  6. 序列化LinkedHashMap,有序输出Json字符串
  7. JAVA EE 第一阶段项目问题
  8. 联系电话正则表达式(jquery表单验证)
  9. Photoshop:去掉投影
  10. eclipse mingw cpp开发环境
  11. VI命令删除文件所有内容
  12. Qt-获取网络接口信息的综合示例
  13. RedHat7安装Sublime Text 3
  14. PC-lint 简明教程
  15. Wowza流媒体Live直播和VOD点播配置实战
  16. 洛谷P3164 [CQOI2014]和谐矩阵
  17. 集合源码分析[2]-AbstractList 源码分析
  18. JS定义一个立即执行的可重用函数
  19. 普通for循环和增强for循环的区别
  20. mybatis由浅入深day01_5.3 Mapper动态代理方法

热门文章

  1. linux 下面avr开发环境的安装
  2. 手势跟踪论文学习:Realtime and Robust Hand Tracking from Depth(三)Cost Function
  3. 将枚举存入map集合
  4. jqGrid收藏的链接
  5. (转载)Android自定义ProgressDialog进度等待框
  6. Glidar: 一个基于OpenGL的开源实时3D传感器仿真器
  7. First-class citizen
  8. 【Computer Vision】角点检测和匹配——Harris算子
  9. python 正则表达式与re模块
  10. 紫书 例题8-15 UVa 12174 (滑动窗口)