Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017年11月23日 00:29:58 -0800

On 23 November 2017 at 09:17, Greg Ewing <[email protected]>
wrote:
> Ivan Levkivskyi wrote:
>
>> "People sometimes want to refactor for-loops containing `yield` into a
>> comprehension
>>
>
> By the way, do we have any real-life examples of people wanting to
> do this? It might help us decide what the semantics should be.
>
>
Yes, there are two SO questions in two first posts here, also there are
some b.p.o. issues. It looks like in all case people expect:
 def f():
 return [(yield i) for i in range(3)]
to be roughly equivalent to
 def f():
 res = []
 for i in range(3):
 r = yield i
 res.append(r)
 return res
See Serhiy's original post for more detailed proposed semantic equivalence.
--
Ivan
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to