Last active
May 28, 2021 20:08
-
-
Save bruno-uy/7ad13eba8f50f27a453a5bb33015b721 to your computer and use it in GitHub Desktop.
Divide iterable in n-size chunks and filter None values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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