[Python]List Comprehension
作者:互联网
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,30,List,信息提取,34,item,students,Comprehension,print 来源: https://www.cnblogs.com/profesor/p/13159955.html