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

[Python]List Comprehension

时间:2020-06-18 21:52:29      阅读:82      评论:0      收藏:0      [点我收藏+]

标签:开头   class   style   int   学生   code   with   err   star   

 

students = [("jerry", 25), ("elaine", 24), ("John", 34), ("kramer", 34)]
#把年龄在30以上的学生信息提取出来
print([item for item in students if item[1] > 30])

#把年龄在30以上的学生姓名提取出来
print([item[0] for item in students if item[1] > 30])

#把名字以j(不论大小写)开头的学生信息提取出来
print([item for item in students if item[0].lower().startswith(j)])

 

[Python]List Comprehension

标签:开头   class   style   int   学生   code   with   err   star   

原文地址:https://www.cnblogs.com/profesor/p/13159955.html

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