> On Fri, Oct 17, 2003 at 11:55:53AM -0600, Shane Holloway (IEEE) wrote: > > mygenerator = x for x in S > > > > for y in x for x in S: > > print y > > > > return x for x in S > > Interesting but potentially confusing: we could expect the last one > to mean that we executing 'return' repeatedly, i.e. returning a > value more than once, which is not what occurs. I'm not sure what you mean by executing 'return' repeatedly; the closest thing in Python is returning a sequence, and this is pretty close (for many practical purposes, returning an iterator is just as good as returning a sequence). > Similarily, > > yield x for x in g() > > in a generator would be quite close to the syntax discussed some > time ago to yield all the values yielded by a sub-generator g, but > in your proposal it wouldn't have that meaning: it would only yield > a single object, which happens to be an iterator with the same > elements as g(). IMO this is not at all similar to what it suggests for return, as executing 'yield' multiple times *is* a defined thing. This is why I'd prefer to require extra parentheses; yield (x for x in g()) is pretty clear about how many times yield is executed. > Even with parenthesis, and assuming a syntax to yield from a > sub-generator for performance reason, the two syntaxes would be > dangerously close: > > yield x for x in g() # means for x in g(): yield x > yield (x for x in g()) # means yield g() I don't see why we need yield x for x in g() when we can already write for x in g(): yield x This would be a clear case of "more than one way to do it". --Guido van Rossum (home page: http://www.python.org/~guido/)
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