Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #42155 > unrolled thread

Re: list comprehension misbehaving

Started byWolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de>
First post2013-03-28 15:52 +0000
Last post2013-03-28 15:52 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: list comprehension misbehaving Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2013-03-28 15:52 +0000

#42155 — Re: list comprehension misbehaving

FromWolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de>
Date2013-03-28 15:52 +0000
SubjectRe: list comprehension misbehaving
Message-ID<mailman.3893.1364485979.2939.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web