[Python-Dev] Coroutines, generators, function calling (original) (raw)
Andrew Koenig ark at acm.org
Thu Oct 20 01:17:05 CEST 2005
- Previous message: [Python-Dev] Coroutines, generators, function calling
- Next message: [Python-Dev] Coroutines, generators, function calling
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
We yield values from inside for loops all over the place, but the yielded value is very rarely just the index value (only 1 of 14 yields) , but something calculated from the index value, so the new syntax would not be useful, unless it was something that provided access to the index item as a variable, like:
yield foo(i) for i in x which barely saves you anything (a colon, a newline, and an indent). (hey wait, isn't that a generator comprehension?
Here's a use case:
def preorder(tree):
if tree:
yield tree
yield from preorder(tree.left)
yield from preorder(tree.right)
- Previous message: [Python-Dev] Coroutines, generators, function calling
- Next message: [Python-Dev] Coroutines, generators, function calling
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]