Skip to content

Instantly share code, notes, and snippets.

@codeliger
Created November 28, 2018 17:20
Show Gist options
  • Save codeliger/2a7ae04612f67dddd580ff4c9147ba41 to your computer and use it in GitHub Desktop.
Save codeliger/2a7ae04612f67dddd580ff4c9147ba41 to your computer and use it in GitHub Desktop.
items = range(0,10001)
def iter_group(iterable, batch_size:int):
iterable_type = type(iterable)
length = len(iterable)
start = batch_size*-1
end = 0
while(end < length):
start += batch_size
end += batch_size
if iterable_type == list:
yield (iterable[i] for i in range(start,min(length-1,end)))
else:
yield iterable[start:end]
for item_group in iter_group(items, 1000):
for item in item_group:
print(item,end=' ')
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment