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: 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 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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