python技巧-通过列表推导构建列表
摘要:
thenewlist=[x+2 for x in theoldlist]thenewlist=[x for x in thelodlist if x >5]thenewlist=[x+2 for x in theoldlist if x>5]L[:]=[min(x,100) for x in L]对每个元素调用一个函数,使用L1=map(function,L)total=sum([x+23 for x in theoldlist if x>32])total=sum(x+23 for x in theoldlist if x>32)也可以。若列表中某元素存在则返回之:d 阅读全文
posted @ 2011-09-21 12:58 zhao896 阅读(212) 评论(0) 推荐(0) 编辑