mirror of https://github.com/mahmoud/boltons.git
Merge branch 'master' of github.com:mahmoud/boltons
This commit is contained in:
commit
331bc690dd
|
@ -218,17 +218,13 @@ def chunked_iter(src, size, **kw):
|
||||||
postprocess = lambda chk: chk
|
postprocess = lambda chk: chk
|
||||||
if isinstance(src, basestring):
|
if isinstance(src, basestring):
|
||||||
postprocess = lambda chk, _sep=type(src)(): _sep.join(chk)
|
postprocess = lambda chk, _sep=type(src)(): _sep.join(chk)
|
||||||
cur_chunk = []
|
src_iter = iter(src)
|
||||||
i = 0
|
while True:
|
||||||
for item in src:
|
cur_chunk = list(itertools.islice(src_iter, size))
|
||||||
cur_chunk.append(item)
|
if not cur_chunk:
|
||||||
i += 1
|
break
|
||||||
if i % size == 0:
|
lc = len(cur_chunk)
|
||||||
yield postprocess(cur_chunk)
|
if lc < size and do_fill:
|
||||||
cur_chunk = []
|
|
||||||
if cur_chunk:
|
|
||||||
if do_fill:
|
|
||||||
lc = len(cur_chunk)
|
|
||||||
cur_chunk[lc:] = [fill_val] * (size - lc)
|
cur_chunk[lc:] = [fill_val] * (size - lc)
|
||||||
yield postprocess(cur_chunk)
|
yield postprocess(cur_chunk)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue