Skip to content

Instantly share code, notes, and snippets.

View fmailhot's full-sized avatar

Fred Mailhot fmailhot

View GitHub Profile
""" Iterate over multiple iterables in batches.
Inspired by 'equivalent' definition of zip in docs here:
https://docs.python.org/3.4/library/functions.html#zip
"""
def group_zip(*iterables, batchsize=2):
# N.B. this truncates to shortest iterable
sentinel = object()
iterators = [iter(it) for it in iterables]