Create a generator that yields values from any number of inner generators

后端 未结 2 1010
轻奢々
轻奢々 2021-01-18 09:34

I have a generator function generate which yields 5 random numbers one at a time. I need to be able to generate the numbers in two ways:

  1. Single g
2条回答
  •  一整个雨季
    2021-01-18 10:10

    you should use itertools.chain.from_iterable

    return itertools.chain.from_iterable(generate(value) for value in values)
    

提交回复
热议问题