Skip to content

Instantly share code, notes, and snippets.

@LowWeiLin
Last active January 26, 2020 07:29
Show Gist options
  • Save LowWeiLin/8c9010d9d0d079921a12a51a70e55cf4 to your computer and use it in GitHub Desktop.
Save LowWeiLin/8c9010d9d0d079921a12a51a70e55cf4 to your computer and use it in GitHub Desktop.
import itertools
def grouper(n, iterable):
it = iter(iterable)
while True:
chunk = tuple(itertools.islice(it, n))
if not chunk:
return
yield chunk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment