[New-bugs-announce] [issue6021] itertools.grouper
report at bugs.python.org
Thu May 14 19:05:31 CEST 2009
New submission from Lie Ryan <lie.1296 at gmail.com>:
An itertool to Group-by-n
>>> lst = range(15)
>>> itertools.grouper(lst, 5)
[[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11, 12, 13, 14]]
This function is often asked in several c.l.py discussions, such as these:
There are several issues. What should be done if the number of items in
the original list is not exactly divisible?
- raise an error as default
- pad with a value from 3rd argument
- make the last one shorter, maybe using keyword arguments or sentinel
to 3rd argument
or should there be separate functions for each of them?
What about infinite list? Most recipes for the function uses zip which
breaks with infinite list.
components: Library (Lib)
type: feature request
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce