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.

classification
Title: Support for splitting lists/tuples into chunks
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.3
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: ezio.melotti, rhettinger, sleepycal
Priority: normal Keywords:

Created on 2011-10-03 18:39 by sleepycal, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
msg144831 - (view) Author: Cal Leeming (sleepycal) Date: 2011-10-03 18:39
After a while of digging around, I noticed that the core libs don't provide an easy way of splitting a list/tuple into chunks - as per the following discussion:

http://www.aspwinhost.com/In-what-way-do-you-split-an-list-into-evenly-sized-chunks-on-Python/

Therefore, I'd like to +1 feature request this.

Any thoughts??

Cal
msg144833 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2011-10-03 18:46
This sounds like the grouper() recipe of itertools.  You could try to convince Raymond and see if he wants to include it in itertools.
msg144834 - (view) Author: Cal Leeming (sleepycal) Date: 2011-10-03 18:56
Oh - and while we are at it - how about having merge_list() and unique_list() as part of the core too??


def unique_list(seq): # Dave Kirby
    # Order preserving
    seen = set()
    return [x for x in seq if x not in seen and not seen.add(x)]
    
def merge_list(seq):
    merged = []
    for s in seq:
        for x in s:
            merged.append(x)
    return merged

Raymond - any thoughts on these 3 requests???

Cal
msg144846 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2011-10-03 22:23
These have been rejected before.  There is always a trade-off in adding tools such as this -- it can take more time to learn and remember them than to write a trivial piece of code to do it yourself.  Another issue is that people tend to disagree on how to handle an odd sized left-over group -- different use cases require different handling.

We're trying to keep the core toolset reasonably small so that python remains simple and learnable.  That raises the threshold for adding new tools.
History
Date User Action Args
2022-04-11 14:57:22adminsetgithub: 57304
2011-10-03 22:23:35rhettingersetstatus: open -> closed
resolution: rejected
messages: + msg144846
2011-10-03 18:56:33sleepycalsetmessages: + msg144834
2011-10-03 18:46:59ezio.melottisetnosy: + rhettinger, ezio.melotti

messages: + msg144833
versions: + Python 3.3
2011-10-03 18:39:55sleepycalcreate