Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #77937
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.009 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; '16,': 0.03; 'element': 0.07; 'iterate': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; 'element.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'iterator': 0.16; 'iterator,': 0.16; 'marker': 0.16; 'popping': 0.16; 'all.': 0.16; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; 'certainly': 0.24; 'cc:2**0': 0.24; 'define': 0.26; 'this:': 0.26; 'gets': 0.27; 'header:In-Reply- To:1': 0.27; 'chris': 0.29; 'message-id:@mail.gmail.com': 0.30; 'that.': 0.31; 'sep': 0.31; 'another': 0.32; 'something': 0.35; 'case,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'subject:data': 0.36; 'yield': 0.36; 'next': 0.36; 'list': 0.37; 'level': 0.37; 'pm,': 0.38; 'that,': 0.38; 'expect': 0.39; 'simply': 0.61; 'advanced': 0.63; 'thomas': 0.65; 'rachel': 0.84; 'thing,': 0.91; 'to:none': 0.92 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=71WWigobLW+/IK2/ns9mPeRnmP8hIpWDMfDEgN3lN2c=; b=N11SEeziQP+POm5fQyepBFcg3IwX3eEXuTCOylBRTJF33+gf6oQewkClRa3ZuZFblj a7X+JDTpifel4y+LavTOUsJ2dSVWer7glNPxytgZHUcqi7hedlr7aQMXoXjy4Y69QVm/ kaNZvNqRIv2nmvCSflUmoIQtFJHX40tirUiwN2F60zoPMupW9TpiQfm0rBnNdWOpZfmt QPHelvVk4ayGYBQPODcn6YNLzFDHIvUgqfih7bb7kl90Vw+IJHNLxE6uT/hvbC18Y/sC cKGMqMUas2o0gHxZi3IJr7XuqxOiXLpr+qaiRhtoLhZn+8J8CKwjdp0w867ZOpHaloz3 z1Ow== |
| MIME-Version | 1.0 |
| X-Received | by 10.50.20.169 with SMTP id o9mr3010716ige.14.1410880768390; Tue, 16 Sep 2014 08:19:28 -0700 (PDT) |
| In-Reply-To | <lv9jcs$vaj$1@r01.glglgl.de> |
| References | <uk3debxpcg.ln2@news.c0t0d0s0.de> <mailman.13990.1410589338.18130.python-list@python.org> <4o6debxojk.ln2@news.c0t0d0s0.de> <mailman.13992.1410592983.18130.python-list@python.org> <lv9jcs$vaj$1@r01.glglgl.de> |
| Date | Wed, 17 Sep 2014 01:19:28 +1000 |
| Subject | Re: Iterator, modify data in loop body |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.14058.1410880778.18130.python-list@python.org> (permalink) |
| Lines | 30 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1410880778 news.xs4all.nl 2958 [2001:888:2000:d::a6]:34329 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:77937 |
Show key headers only | View raw
On Tue, Sep 16, 2014 at 6:49 PM, Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> wrote: > Am 13.09.2014 09:22 schrieb Chris Angelico: > >> In that case, don't iterate over the list at all. Do something like this: >> >> while lst: >> element = lst.pop(0) >> # work with element >> lst.append(new_element) > > > And if you don't like that, define a > > def iter_pop(lst): > while lst: > yield lst.pop(0) > > and you can do > > for element in iter_pop(lst): But that's exactly the same thing, with another level of indirection. It certainly isn't the advantage you'd expect from an iterator, namely that it simply stores a marker that gets advanced to the next element. Popping the 0th element is costly, wrapping it into an iterator conceals that. ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Iterator, modify data in loop body Michael Welle <mwe012008@gmx.net> - 2014-09-13 08:09 +0200
Re: Iterator, modify data in loop body Chris Angelico <rosuav@gmail.com> - 2014-09-13 16:22 +1000
Re: Iterator, modify data in loop body Michael Welle <mwe012008@gmx.net> - 2014-09-13 09:01 +0200
Re: Iterator, modify data in loop body Chris Angelico <rosuav@gmail.com> - 2014-09-13 17:22 +1000
Re: Iterator, modify data in loop body Michael Welle <mwe012008@gmx.net> - 2014-09-13 09:39 +0200
Re: Iterator, modify data in loop body Ian Kelly <ian.g.kelly@gmail.com> - 2014-09-13 09:27 -0600
Re: Iterator, modify data in loop body Michael Welle <mwe012008@gmx.net> - 2014-09-13 18:58 +0200
Re: Iterator, modify data in loop body Chris Angelico <rosuav@gmail.com> - 2014-09-14 01:32 +1000
Re: Iterator, modify data in loop body Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2014-09-16 10:49 +0200
Re: Iterator, modify data in loop body Chris Angelico <rosuav@gmail.com> - 2014-09-17 01:19 +1000
Re: Iterator, modify data in loop body Peter Otten <__peter__@web.de> - 2014-09-13 09:34 +0200
Re: Iterator, modify data in loop body Michael Welle <mwe012008@gmx.net> - 2014-09-13 09:55 +0200
csiph-web