Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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; 'output': 0.05; 'subject:PEP': 0.07; 'chunk': 0.09; 'item.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'useless': 0.09; 'worse': 0.09; 'jan': 0.12; '2.2,': 0.16; 'item)': 0.16; 'iterables': 0.16; 'iterating': 0.16; 'iterators': 0.16; 'iterators,': 0.16; 'mylist': 0.16; 'objection': 0.16; 'parameter.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'stuff.': 0.16; 'index': 0.16; 'wrote:': 0.18; 'meant': 0.20; 'written': 0.21; 'example': 0.22; 'proposed': 0.22; 'header:User-Agent:1': 0.23; 'sort': 0.25; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply- To:1': 0.27; 'am,': 0.29; 'usually': 0.31; '(optional)': 0.31; 'argue': 0.31; 'once,': 0.31; 'lists': 0.32; 'subject:from': 0.34; 'basic': 0.35; 'something': 0.35; 'subject:lists': 0.35; 'add': 0.35; 'doing': 0.36; 'useful': 0.36; 'should': 0.36; 'list': 0.37; 'list.': 0.37; 'being': 0.38; 'lists.': 0.38; 'to:addr:python- list': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'remove': 0.60; 'new': 0.61; 'today,': 0.61; 'received:173': 0.61; 'first': 0.61; 'jobs': 0.68; 'end.': 0.84; 'received:fios.verizon.net': 0.84; 'seldom': 0.84; 'thing,': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Suggestion: PEP for popping slices from lists Date: Thu, 08 Aug 2013 16:03:27 -0400 References: <531d89a8-61e1-4117-b4cc-f02b3be30bb9@googlegroups.com> <9bd6192b-2c71-4662-808a-fd7e74dedeb8@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 In-Reply-To: <9bd6192b-2c71-4662-808a-fd7e74dedeb8@googlegroups.com> 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: 49 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1375992220 news.xs4all.nl 15932 [2001:888:2000:d::a6]:47521 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:52225 On 8/8/2013 7:44 AM, Neatu Ovidiu wrote: Objection 1. People usually want to chunk sequences, not lists specifically. We now try to add new features that work with iterators and iterables generally, not just lists. > This can be useful for doing all kinds of basic stuff. For example if you wanted to take 4 items of a list at at a time, do something with them and then update the list. > > jobs = ['job1', 'job2', 'job3', 'job4', 'job5', 'job6', 'job7', 'job8', 'job9', 'job10'] > while jobs: > print(jobs.pop_slice(0,4)) > > should output > > 'job1', 'job2', 'job3', 'job4' > 'job5', 'job6', 'job7', 'job8' > 'job9', 'job10' Objection 2. Usually when one wants to do this sort of thing, one wants the list either be intact or empty at the end. Emptying it chunk by chunk is worse than useless because it turns an O(n) process into an O(n*n) process. The same is true of destructively iterating through a list with .pop(0). When I proposed the addition of .pop(), I meant it as the inverses of .append and did not include the (optional) index parameter. It is seldom used and usually only once, to remove a single leading item. The addition of iterators, which occurred *after* the addition of .pop, replaced some uses of .pop(0). For instance first = mylist.pop(0) # O(N) operation for item in mylist: process(first, item) del mylist can, since 2.2, be written as it = iter(mylist) first = next(it) # O(1) operation for item in it: process(first, item) del mylist If .pop were being added today, I would argue against including the index parameter. -- Terry Jan Reedy