Skip to content

Instantly share code, notes, and snippets.

@maxpoletaev
Created May 22, 2019 12:04
Show Gist options
  • Save maxpoletaev/06a6008e4bf41f727d7ee80d76ac9853 to your computer and use it in GitHub Desktop.
Save maxpoletaev/06a6008e4bf41f727d7ee80d76ac9853 to your computer and use it in GitHub Desktop.
def chunked(data, n):
for x in range(0, len(data), n):
yield data[x:x+n]
if __name__ == '__main__':
assert list(chunked([1, 2, 3, 4, 5], 2)) == [[1, 2], [3, 4], [5]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment