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.27698e-09
Marked as misclassified No
Message-id <>
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 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.
Date User Action Args
2009-05-14 17:05:31lieryansetrecipients: + lieryan
2009-05-14 17:05:31lieryansetmessageid: <>
2009-05-14 17:05:29lieryanlinkissue6021 messages
2009-05-14 17:05:28lieryancreate