【发布时间】:2012-08-29 20:26:36
【问题描述】:
您好,我正在使用 python 的 itertools 中的 Grouper 函数来减少大量 select where in(idlist) 查询以提高 sqlite 性能。问题是即使列表小得多,grouper 也会填充块大小的整个空间,所以我必须添加一个循环和比较,在此之前我要优化。
# input list shorter than grouper chunk size
input = (1,2,3,4,5)
grouper(10,input)
# desired output = (1,2,3,4,5)
# actual output = (1,2,3,4,5,None,None,None,None,None)
# current fix for this issue
list_chunks = tuple(tuple(n for n in t if n) for t in grouper(10, input))
我认为必须有一种方法可以在没有这种循环和比较的情况下做到这一点。
注意:使用python 2.5
【问题讨论】:
标签: python python-2.5 itertools python-2.4