I'm wondering how I can write a generator function that also has the option to return a value. In Python 2, you get the following error message if a generator function tries to return a value. SyntaxError: 'return' with argument inside generator
Is it possible to write a function where I specify if I want to receive a generator or not?
For example:
def f(generator=False):
if generator:
yield 3
else:
return 3