作者ZolaEmile (Zola)
看板Python
标题Re: [问题] list中插入资料效能的问题
时间Tue Feb 21 17:00:03 2017
我不确定是不是你要的:
from time import time
old = [str(i) for i in range(10**7)] # set up a list
insert = ['n'] # set up an insert list
def test(old, insert):
t0 = time()
add = (old[i : i + 1024] + insert for i in range(0, len(old), 1024))
new = []
for i in range(0, len(old), 1024):
new += next(add)
print(time() - t0)
return new
new = test(old, insert)
输出结果:
0.2487800121307373
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 42.73.157.3
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1487667606.A.6B4.html