[Python-ideas] itertools.chunks()

Wolfgang Maier wolfgang.maier at biologie.uni-freiburg.de
Sun Apr 7 11:37:50 CEST 2013


>Also I find myself often writing helper functions like these:
>
>def chunked(sequence,size):
>	i = 0
>	while True:
>		j = i
>		i += size
>		chunk = sequence[j:i]
>		if not chunk:
>			return
>		yield chunk

This is just an alternate version of the grouper recipe from the itertools
documentation, just that grouper should be way faster and will also work
with iterators.
We just had a thread on variations of the grouper recipe under *zip_strict()
or similar in itertools*.

Wolfgang




More information about the Python-ideas mailing list