This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author lieryan
Recipients lieryan
Date 2009-05-14.17:05:28
SpamBayes Score 5.2769806e-09
Marked as misclassified No
Message-id <1242320731.02.0.157515578486.issue6021@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2009-05-14 17:05:31lieryansetrecipients: + lieryan
2009-05-14 17:05:31lieryansetmessageid: <1242320731.02.0.157515578486.issue6021@psf.upfronthosting.co.za>
2009-05-14 17:05:29lieryanlinkissue6021 messages
2009-05-14 17:05:28lieryancreate