On Wed, 22 Nov 2017 15:03:09 +0200 Serhiy Storchaka <storchaka at gmail.com> wrote: > From > https://stackoverflow.com/questions/45190729/differences-between-generator-comprehension-expressions. > > g = [(yield i) for i in range(3)] > > Syntactically this looks like a list comprehension, and g should be a > list, right? But actually it is a generator. This code is equivalent to > the following code: > > def _make_list(it): > result = [] > for i in it: > result.append(yield i) > return result > g = _make_list(iter(range(3))) > > Due to "yield" in the expression _make_list() is not a function > returning a list, but a generator function returning a generator. > > This change in semantic looks unintentional to me. It looks like leaking > an implementation detail. Perhaps we can deprecate the use of "yield" in comprehensions and make it a syntax error in a couple versions? I don't see a reason for writing such code rather than the more explicit variants. It looks really obscure, regardless of the actual semantics. Regards Antoine.
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