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


Groups > comp.lang.python > #60519 > unrolled thread

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

Started byChris Angelico <rosuav@gmail.com>
First post2013-11-27 02:14 +1100
Last post2013-11-27 02:14 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

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

FromChris Angelico <rosuav@gmail.com>
Date2013-11-27 02:14 +1100
SubjectRe: [Python-ideas] Using yield inside a comprehension.
Message-ID<mailman.3244.1385478846.18130.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web