4 ms·
I totally agree with you on the core issue. However, I would reject your `chunks` function in a code review and tell you to use `grouper` form the itertools re
by kilburn 11y ago
I totally agree with you on the core issue.
However, I would reject your `chunks` function in a code review and tell you to use `grouper` form the itertools recipes [1].
More generally,any time I've ended up with a long list comprehension, the answer has been to "check itertools and see how you would describe this ugly comprehension in those terms"
[1] https://docs.python.org/3/library/itertools.html#itertools-recipes https://docs.python.org/3/library/itertools.html#itertools-r...
- unoti 11y agoGrouper is a recipe, it's not part of itertools. It probably should be!
- thomasahle 11y agoAll of the recipes in the itertools documentation should pretty much be considered folklore imho. If you always use the 'zip((iterator,)n)' approach, people will recognize it and know immediately what you mean.