zhao896

 

2011年9月21日

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 阅读(211) 评论(0) 推荐(0) 编辑

python技巧-对象拷贝

摘要: 1. 普通浅拷贝在知道对象类型时,使用t[:], [x for x in t] , t+[], t*1 等都是浪费时间和内存。直接用类型如list,t1= list(t)就可以了,d1=dict(d).不知道类型情况下,使用copy.copy(t)2. is 对于不可变类型毫无意义,对可变类型判断是不同对象还是引用同一个对象,可以简单找到答案。 阅读全文

posted @ 2011-09-21 10:36 zhao896 阅读(514) 评论(0) 推荐(0) 编辑

2007年8月26日

刚加入博客园

摘要: 要好好向各位高手学习。 阅读全文

posted @ 2007-08-26 19:59 zhao896 阅读(138) 评论(3) 推荐(0) 编辑

导航