码迷,mamicode.com
首页 > 其他好文 > 详细

List exercise

时间:2014-07-15 09:12:42      阅读:328      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   2014   for   io   

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

标签:style   blog   http   2014   for   io   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!