Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.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; 'broken': 0.04; 'feedback.': 0.04; 'guido': 0.05; 'expressions': 0.07; 'generators': 0.09; 'pep': 0.09; 'cc:addr:python-list': 0.11; 'cc:name:python list': 0.16; 'expressions,': 0.16; 'inclined': 0.16; 'iterable)': 0.16; 'roy': 0.16; 'subject:Different': 0.16; 'subject:expressions': 0.16; 'subject:generator': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'url:peps': 0.16; 'eager': 0.16; 'wrote:': 0.18; 'examples': 0.20; 'cc:addr:python.org': 0.22; 'url:dev': 0.24; 'mon,': 0.24; 'cc:2**0': 0.24; 'handling': 0.26; 'post': 0.26; 'header:In-Reply-To:1': 0.27; 'subject:list': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'asked': 0.31; 'code': 0.31; 'comments': 0.31; "d'aprano": 0.31; 'raised': 0.31; 'steven': 0.31; 'anyone': 0.31; 'url:python': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'thanks': 0.36; 'url:org': 0.36; 'should': 0.36; 'detail': 0.37; 'list': 0.37; 'being': 0.38; 'nov': 0.38; 'pm,': 0.38; 'forwarded': 0.39; 'read': 0.60; 'expression': 0.60; 'impact': 0.61; 'interested,': 0.61; 'here:': 0.62; 'soon': 0.63; 'different.': 0.84 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:to :cc:content-type; bh=C2xmxEYQOiEgu0L19A086Zj/x6NFunGpXYDdkQjVLwU=; b=LhrclOFWbVJn0+qQ7ZtTa1bs/wQF7n8Ver7LXghpskDoQOWoBoQwJ9IC4dQRvyePE0 5AlpD9ao5JsyC6S5gyIDw0+s/+SiLDtUxBFBXA3eTIrd/7uBukVAs1x6xfYntDOpyMnz ofmcrEoqYRIucLKSFrAk1IUR+i/VQA7sp5tqPHJDoP5eJrinNj2PyVmELJkLIQ441v9x wAg2LarK4adggJsFZ8+ZfHxjJicQR5wrhhD4f0j7BUOOGhbBOm/nktNQsxqdSAFDuxgO ttU+gtyTaiU4wVfZXJq1diwTxPx8aRZTLhFGyH6Cknbc6WEVSCtU+/ldDXMdZZlBEwSj xHeQ== MIME-Version: 1.0 X-Received: by 10.152.10.67 with SMTP id g3mr31922726lab.59.1416267539705; Mon, 17 Nov 2014 15:38:59 -0800 (PST) In-Reply-To: <546a8524$0$12990$c3e8da3$5496439d@news.astraweb.com> References: <545d76fe$0$12980$c3e8da3$5496439d@news.astraweb.com> <546a8524$0$12990$c3e8da3$5496439d@news.astraweb.com> Date: Mon, 17 Nov 2014 15:38:59 -0800 Subject: Re: Different behaviour in list comps and generator expressions From: Dan Stromberg To: "Steven D'Aprano" Content-Type: text/plain; charset=UTF-8 Cc: Python List 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: 1416267547 news.xs4all.nl 2919 [2001:888:2000:d::a6]:46880 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80988 On Mon, Nov 17, 2014 at 3:30 PM, Steven D'Aprano wrote: >> The following list comprehension and generator expression are almost, but >> not quite, the same: >> >> [expr for x in iterable] >> >> list(expr for x in iterable) >> >> >> The difference is in the handling of StopIteration raised inside the expr. > [...] > > > Thanks to Roy and Wolfgang for their comments. > > If anyone is interested, Guido will soon be ruling on a PEP which will > change the behaviour of generators and generator expressions, and he has > asked for feedback. In particular, examples of code which will be broken by > this change. > > Read the PEP here: > > https://www.python.org/dev/peps/pep-0479 > > > If you post comments here, I will see that they get forwarded on. I'm inclined to say that list comprehensions and generator expressions should be different. I don't really think they should be identical, one being eager and one being lazy. Why let the implementation detail of one impact the other?