Python 列表开销优化

a里面的测试表明了一个问题,定态分配的list快过列表推导式快过append重复调用. 这说明有的时候用列表推导式而不是append可以加速代码.

然后是静态生成. 理论上说,在任何情况下,这个都比列表推导式和append快,而且实际上就是快. 这很好理解,静态生成不需要扩张大小,尤其是list的大小重分配是一个很频繁的问题.

列表推导式和append之间关系

def join3(n):
b = []
for i in xrange(n): b.append(a[i])
# return ''.join(b)

def join4(n):
b = [a[i] for i in xrange(n)]
# return ''.join(b)

for n in xrange(1, 40, 2):

阅读更多

2013-05-28   Think   

Combination

  • hi GDG guys
  • Cnglish again!
  • i’m Zoom.Quiet, come from China, as GDG ZhuHai Organizer
  • my Barcamp topic is:
    • base ‘L10N’ make GDG chapters
  • and pay attention, my slides is base s5,its pure html page
    • so had released into internat
    • thit is the URL
    • http://zoomquiet.org/res/s5/130512-gdgsummit/

Zoom.Quiet

  • yep,i know the Zoom.Quiet is error name
  • but again,its my realy NikName
  • and base the error name , i hold the global unique id !
  • so the logo is show about what my error name realy means

disclaimer

阅读更多

2013-05-13   Think   


最新文章

网站