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


Groups > comp.lang.python > #42147

list comprehension misbehaving

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'explicit': 0.07; '[1,': 0.09; '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; 'working:': 0.09; 'python': 0.11; '2.7': 0.14; 'message-id:@post.gmane.org': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'all,': 0.19; '(in': 0.22; 'header:User-Agent:1': 0.23; 'equivalent': 0.26; 'header:X -Complaints-To:1': 0.27; '[1]': 0.29; '???': 0.30; 'subject:list': 0.30; 'received:132': 0.31; 'but': 0.35; 'charset:us-ascii': 0.36; 'thanks': 0.36; 'two': 0.37; 'to:addr:python-list': 0.38; 'help,': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'dear': 0.65
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de>
Subject list comprehension misbehaving
Date Thu, 28 Mar 2013 15:25:14 +0000 (UTC)
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.3887.1364484337.2939.python-list@python.org> (permalink)
Lines 32
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1364484337 news.xs4all.nl 6910 [2001:888:2000:d::a6]:48361
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:42147

Show key headers only | View raw


Dear all, with
a=list(range(1,11))

why (in Python 2.7 and 3.3) is this explicit for loop working:
for i in a[:-1]:
    a.pop() and a

giving:
[1, 2, 3, 4, 5, 6, 7, 8, 9]
[1, 2, 3, 4, 5, 6, 7, 8]
[1, 2, 3, 4, 5, 6, 7]
[1, 2, 3, 4, 5, 6]
[1, 2, 3, 4, 5]
[1, 2, 3, 4]
[1, 2, 3]
[1, 2]
[1]

but the equivalent comprehension failing:
[a.pop() and a for i in a[:-1]]

giving:
[[1], [1], [1], [1], [1], [1], [1], [1], [1]]

???
Especially, since these two things *do* work as expected:
[a.pop() and a[:] for i in a[:-1]]
[a.pop() and print(a) for i in a[:-1]] # Python 3 only

Thanks for your help,
Wolfgang

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

list comprehension misbehaving Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2013-03-28 15:25 +0000
  Re: list comprehension misbehaving duncan smith <buzzard@invalid.invalid> - 2013-03-28 15:54 +0000

csiph-web