码迷,mamicode.com
首页 > 编程语言 > 详细

Python小记

时间:2017-03-07 22:44:58      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:python   out   div   span   key   list   and   range   turn   

赛选回文数

def is_palindrome(num):
    return num > 9 and str(num) == str(num)[::-1]
output = filter(is_palindrome,range(1,10000))
print(list(output)) 

 对L = [(‘Bob‘, 75), (‘Adam‘, 92), (‘Bart‘, 66), (‘Lisa‘, 88)]分别按名字和分数排序

L = [(Bob, 75), (Adam, 92), (Bart, 66), (Lisa, 88)]
def by_name(t):
    return t[0]
def by_score(t):
    return t[1]
print(sorted(L,key=by_score)) #[(‘Bart‘, 66), (‘Bob‘, 75), (‘Lisa‘, 88), (‘Adam‘, 92)]
print(sorted(L,key=by_name)) #[(‘Adam‘, 92), (‘Bart‘, 66), (‘Bob‘, 75), (‘Lisa‘, 88)]

#print(sorted(L,key=lambda x:x[0]))
#print(sorted(L,key=lambda x:x[1]))
 

 

Python小记

标签:python   out   div   span   key   list   and   range   turn   

原文地址:http://www.cnblogs.com/jp-mao/p/6517049.html

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