- Fix chunks for when length of input is smaller than chunk size.

This commit is contained in:
Wim Pomp
2020-11-24 16:34:40 +01:00
parent 2ddf73ed0f
commit a02677dc1d
3 changed files with 6 additions and 3 deletions

View File

@@ -118,8 +118,8 @@ def chunks(n, *args):
""" Yield successive n-sized chunks from lists. """
A = len(args)==1
N = len(args[0])
n = int(round(N/round(N/n)))
for i in range(0, N, n):
n = int(round(N/max(1, round(N/n))))
for i in range(0, N, n) if N else []:
if A:
yield args[0][i:i+n]
else: