[Python-ideas] itertools.chunks()

Wolfgang Maier wolfgang.maier at biologie.uni-freiburg.de
Mon Apr 8 13:00:54 CEST 2013


Wolfgang Maier <wolfgang.maier at ...> writes:

ok, I did time things now, comparing chunked and Peter Otten's
strict_grouper (see the before-mentioned earlier thread). I used lists of
integers as input sequences.
strict_grouper has a bit more overhead at the start because it needs to
obtain an iterable from the sequence, but then it's running fast.
The break-even point is at about ten runs of the respective generator loops.
For very long sequences strict_grouper is more than 2x faster than chunked.
So, in the special case that one wants to group many short sequences chunked
is better, but it's not the best general solution.

Wolfgang







More information about the Python-ideas mailing list