Wednesday, 16 May 2018

python - Return or yield from a function that calls a generator?

I have a generator generator and also a convenience method to it - generate_all.



def generator(some_list):

for i in some_list:
yield do_something(i)

def generate_all():
some_list = get_the_list()
return generator(some_list) # <-- Is this supposed to be return or yield?


Should generate_all return or yield? I want the users of both methods to use it the same, i.e.




for x in generate_all()


should be equal to



some_list = get_the_list()
for x in generate(some_list)

No comments:

Post a Comment

casting - Why wasn&#39;t Tobey Maguire in The Amazing Spider-Man? - Movies &amp; TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...