[New-bugs-announce] [issue6021] itertools.grouper

Lie Ryan 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: 
http://comments.gmane.org/gmane.comp.python.general/623377
http://comments.gmane.org/gmane.comp.python.general/622763

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)
messages: 87743
nosy: lieryan
severity: normal
status: open
title: itertools.grouper
type: feature request

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6021>
_______________________________________


More information about the New-bugs-announce mailing list