Skip to content

Instantly share code, notes, and snippets.

@bruno-uy
Last active May 28, 2021 20:08
Show Gist options
  • Save bruno-uy/7ad13eba8f50f27a453a5bb33015b721 to your computer and use it in GitHub Desktop.
Save bruno-uy/7ad13eba8f50f27a453a5bb33015b721 to your computer and use it in GitHub Desktop.
Divide iterable in n-size chunks and filter None values
# Remember to install more_itertools first
# pip install more-itertools
from more_itertools import grouper
def do_something_with_iterable(iterable):
pass
n = 3
chunks = grouper('a'*10, n)
for c in chunks:
if None in c:
c = tuple(filter(None, c))
do_something_with_iterable(c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment