A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2017-November/150747.html below:

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

[Python-Dev] Tricky way of of creating a generator via a comprehension expression [Python-Dev] Tricky way of of creating a generator via a comprehension expressionSven R. Kunze srkunze at mail.de
Thu Nov 23 02:51:44 EST 2017
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20171123/844f3700/attachment.html>
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4