[Python-Dev] Tricky way of of creating a generator via a comprehension expression (original) (raw)

Ivan Levkivskyi levkivskyi at gmail.com
Thu Nov 23 03:26:26 EST 2017


On 23 November 2017 at 09:17, Greg Ewing <greg.ewing at canterbury.ac.nz> 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20171123/2140fcec/attachment.html>



More information about the Python-Dev mailing list