首页 > 其他 > 详细

List exercise

时间:2014-07-15 09:13:02      阅读:395      评论:0      收藏:0      [点我收藏+]

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

 bubuko.com,布布扣

                       

 

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

 bubuko.com,布布扣

.

 

from Thinking in Python

List exercise,布布扣,bubuko.com

List exercise

原文:http://www.cnblogs.com/ryansunyu/p/3841586.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!