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


Groups > comp.lang.python > #60519

Re: [Python-ideas] Using yield inside a comprehension.

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'python.': 0.02; 'subject:: [': 0.04; 'syntax': 0.04; 'subject:Python': 0.06; 'pep': 0.09; 'subject:skip:c 10': 0.09; 'assume': 0.14; 'posted': 0.15; 'assigns': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject:ideas': 0.16; 'subject:yield': 0.16; 'weird': 0.16; 'all.': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'subject:] ': 0.20; 'equivalent': 0.26; 'this:': 0.26; 'post': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'statement': 0.30; 'message-id:@mail.gmail.com': 0.30; 'maybe': 0.34; 'something': 0.35; 'no,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'list': 0.37; 'list.': 0.37; 'nov': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'first': 0.61; 'such': 0.63; 'interest': 0.64; 'confusing': 0.84; 'describes': 0.84; 'subject:Using': 0.84; 'thing,': 0.91; '2013': 0.98
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 :content-type; bh=k29X4OKonJJlGLc70BWmMfSuRHZ6Wr7nCJFlQY640U8=; b=Xrnmzmh2w2Bh5O2udN09kR3es+1JTCBSb6Ht6F5288CpR9pnCl9EpNOAPixTQJYq3w vJjM+yvVdSfuvAO7rYkN3dGqoKauOhyqrswnV5n4490R68qcSXGJoaAO/QX/rijHkpVv OAqDlQhIVJ4m+dDEZ99tIg5fzMc5SaT+6q3AA5VSS9UFhjXsHjrgB+UmQjkfu+hh/ds0 vq8SD9ddISxAbUCjEB9Vd8/qVZGy74SVrvlHy//L04Wsp4VN5ZeUfFGtU9YGSzpBjPFZ +jsU49DihnVNYWwibr/FjAwjrtBeP7jKO1IffJNrekKpAwGY3tOKbH8TcfbLdwmFRHgz pMWw==
MIME-Version 1.0
X-Received by 10.66.26.106 with SMTP id k10mr11383938pag.136.1385478842644; Tue, 26 Nov 2013 07:14:02 -0800 (PST)
In-Reply-To <CAPTjJmrYjrb+DFw13zC+5s_SzvsxC=YnTfpQjQNEy_QgKhRVpA@mail.gmail.com>
References <CAKfyG3zUEfvaK5CYUB2sVw9MvCkxpbzvFYn8Gqn2vtZUjbLD=g@mail.gmail.com> <CAPTjJmrYjrb+DFw13zC+5s_SzvsxC=YnTfpQjQNEy_QgKhRVpA@mail.gmail.com>
Date Wed, 27 Nov 2013 02:14:02 +1100
Subject Re: [Python-ideas] Using yield inside a comprehension.
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
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 <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3244.1385478846.18130.python-list@python.org> (permalink)
Lines 21
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1385478847 news.xs4all.nl 15895 [2001:888:2000:d::a6]:45823
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:60519

Show key headers only | View raw


On Wed, Nov 27, 2013 at 1:26 AM, Chris Angelico <rosuav@gmail.com> wrote:
> On Wed, Nov 27, 2013 at 12:54 AM, Jonathan Slenders
> <jonathan@slenders.be> wrote:
>> Where do I find the PEP that describes that the following statement assigns
>> a generator object to `values`?
>> values = [ (yield x) for x in range(10) ]
>>
>> I assume it's equivalent to the following:
>> values = (x for x in range(10))
>
> No, it's not the same; after yielding the ten values, the first one
> then _returns_ the list. It's a weird and confusing syntax to use for
> such a thing, but fundamentally it's (more or less) this:

Doh, when am I going to learn to check which list something was posted
on before I respond? SIGH. Sorry all.

But hey. Maybe the post will have been of interest to someone. It's a
fun quirk of Python.

ChrisA

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


Thread

Re: [Python-ideas] Using yield inside a comprehension. Chris Angelico <rosuav@gmail.com> - 2013-11-27 02:14 +1100

csiph-web