Python generator to yield everything from another generator call

前端 未结 4 740
星月不相逢
星月不相逢 2021-01-07 19:26

I have a Python generator that can call itself to get more elements to yield. It looks like this:

def gen(list):
    # ...
    if list:
        for x in gen         


        
4条回答
  •  太阳男子
    2021-01-07 20:03

    There's been some call for a yield from or the like that "passes through" all the values returned by a subgenerator. See PEP 380 for some ideas that have been bounced around. However, nothing has been implemented yet. Your first example is correct.

提交回复
热议问题