How to return a generator from another function
问题 I have a generator function which I want to call from another function and return the generator obtained. I can see two approaches here - Note that the below functions are simple dummy functions to illustrate the purpose. Please don't come up with better ways to implement those functions itself. Method 1 def fun_a(n): for i in range(n): yield i+10 def fun_b(n): if n < 0: yield None return yield fun_a(n) and use it as list(list(fun_b(10))[0]) to get [10, 11, 12, 13, 14, 15, 16, 17, 18, 19]