Is there any shorthand for 'yield all the output from a generator'?

后端 未结 3 527
死守一世寂寞
死守一世寂寞 2021-01-17 07:34

Is there a one-line expression for:

for thing in generator:
    yield thing

I tried yield generator to no avail.

3条回答
  •  时光取名叫无心
    2021-01-17 08:18

    You can use a list comprehension to get all of the elements out of a generator (assuming the generator ends):

    [x for x in generator]
    

提交回复
热议问题