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.

References <CAKfyG3zUEfvaK5CYUB2sVw9MvCkxpbzvFYn8Gqn2vtZUjbLD=g@mail.gmail.com> <CAPTjJmrYjrb+DFw13zC+5s_SzvsxC=YnTfpQjQNEy_QgKhRVpA@mail.gmail.com>
Date 2013-11-27 02:14 +1100
Subject Re: [Python-ideas] Using yield inside a comprehension.
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.3244.1385478846.18130.python-list@python.org> (permalink)

Show all headers | 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