Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:not': 0.03; 'sized': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:Why': 0.09; 'def': 0.12; '3],': 0.16; 'chunks': 0.16; 'iterator': 0.16; 'range(0,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'size):': 0.16; 'url:312443': 0.16; 'url:djangoproject': 0.16; 'url:how-do-you-split-a-list- into-evenly-sized-chunks-in-python': 0.16; 'subject:python': 0.16; 'split': 0.19; 'python?': 0.22; 'header:User-Agent:1': 0.23; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'url:code': 0.29; 'subject:the': 0.34; 'library.': 0.36; 'subject:?': 0.36; 'should': 0.36; 'list': 0.37; '8bit%:86': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'kind': 0.63; 'url:ticket': 0.84; 'mistakes': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Serhiy Storchaka Subject: Re: Why chunks is not part of the python standard lib? Date: Wed, 01 May 2013 19:19:07 +0300 References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: 37.19.199.183 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130329 Thunderbird/17.0.5 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 18 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1367425160 news.xs4all.nl 15871 [2001:888:2000:d::a6]:44609 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:44596 01.05.13 09:26, Ricardo Azpeitia Pimentel написав(ла): > After reading How do you split a list into evenly sized chunks in > Python? > > and seeing this kind of mistakes happening > https://code.djangoproject.com/ticket/18972 all the time. > > Why is not a |chunks| function in itertools? Because not every 1 line function needs to be in the standard library. > |chunks([1, 2, 3, 4, 5], 3) > # Should return [[1, 2, 3], [4, 5]] or the iterator equivalent.| def chunks(seq, size): return [seq[i: i + size] for i in range(0, len(seq), size)]