(original) (raw)
On 23.11.2017 08:38, Ivan Levkivskyi wrote:I think this code should be just equivalent to this code
def g():temp = \[(yield i) for i in range(10)\]return (v for v in temp)
Semantics of the comprehension should be clear here (just an equivalent for-loop without name leaking)
Excuse me if I disagree here. If I were to understand this in real-world code, I cannot imagine what will happen here.
A "yield" within a comprehension is like a "return" in a comprehension. It makes no sense at all.
Also a "yield" and a "return with value" is also rarely seen.
Comprehensions build new objects, they are not for control flow, IMO.
Cheers,
Sven