human
I am working on the file "03-yield-from-syntax-for-delegating-to-subgenerator.ipynb".
The first task is:
Value of the yield from expression
Just like yield, the yield from construct can be used as an expression. It can be assigned to a variable, passed to another function, etc.
The value is the object that gets returned as the subgenerator exits, or the .value attribute of the raised StopIteration.
Again ignoring the semantics of send() and throw(), this means that RESULT = yield from EXPR is similar to the following code.
python
iter = (EXPR).__iter__()
running = True
while running:
    try:
        yield iter.__next__()
    except StopIteration as exc:
        RESULT = exc.value
        running = False
Can you write Python program for it?
assistant
#Here is the Python program you requested.

def subgenerator():
    yield 'yielded_value'
    yield '1'
    yield '2'
    return 'returned_value'

def generator():
    value = yield from subgenerator()
    print('generator received final return value', value, 'from subgenerator')
    
for item in generator():
    print('generator yielded', item)

import collections

class SubGenerator(collections.Generator):
    def send(self, value):
        raise StopIteration('returned_value')
    def throw(self, *exc_info):
        next(self)
        
        
def generator():
    value = yield from SubGenerator()
    print('generator received final return value', value, 'from SubGenerator')
    
    
for item in generator():
    pass