Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #42155
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.020 |
| X-Spam-Evidence | '*H*': 0.96; '*S*': 0.00; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:skip:c 10': 0.09; '"a"': 0.16; '-tkc': 0.16; 'loop.': 0.16; 'message-id:@post.gmane.org': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'tim,': 0.16; 'thanks,': 0.17; 'print': 0.22; 'header:User- Agent:1': 0.23; 'refers': 0.24; 'header:X-Complaints-To:1': 0.27; 'tim': 0.29; 'subject:list': 0.30; "i'm": 0.30; 'getting': 0.31; 'chase': 0.31; 'end,': 0.31; 'received:132': 0.31; 'writes:': 0.31; 'but': 0.35; 'charset:us-ascii': 0.36; 'thanks': 0.36; 'example,': 0.37; 'list': 0.37; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'middle': 0.60; "you're": 0.61; 'first': 0.61; 'skip:n 10': 0.64; 'taking': 0.65; 'results': 0.69; 'obvious.': 0.84; 'snapshot': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> |
| Subject | Re: list comprehension misbehaving |
| Date | Thu, 28 Mar 2013 15:52:29 +0000 (UTC) |
| References | <loom.20130328T160914-263@post.gmane.org> <20130328104451.22bad9af@bigbox.christie.dr> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | sea.gmane.org |
| User-Agent | Loom/3.14 (http://gmane.org/) |
| X-Loom-IP | 132.230.1.31 (Mozilla/5.0 (Windows NT 6.1; rv:19.0) Gecko/20100101 Firefox/19.0) |
| 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 | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3893.1364485979.2939.python-list@python.org> (permalink) |
| Lines | 26 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1364485979 news.xs4all.nl 6899 [2001:888:2000:d::a6]:47672 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:42155 |
Show key headers only | View raw
Tim Chase <python.list <at> tim.thechases.com> writes: > it's because you're taking a snapshot copy of "a" in the middle of > the loop. In your first example, if you change it to > > results = [] > for i in a[:-1]: > results.append(a.pop() and a) > print results > > you get the same thing as your list comprehension because each item > in "results" refers to the now-(mostly)empty "a". > > -tkc > > Hi Tim, and thanks a lot for helping! I got it: in the comprehension case I'm only getting my results at the end, when my list has been emptied! Thanks, I got stuck with this, but now it's obvious. Best, Wolfgang
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: list comprehension misbehaving Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2013-03-28 15:52 +0000
csiph-web