I have a Python generator that can call itself to get more elements to yield. It looks like this:
def gen(list):
# ...
if list:
for x in gen(list[1:]):
yield x
My question is about the last two lines: is there a more concise way to express this? I am hoping for something like this (understanding this isn't valid Python as-is):
def gen(list):
# ...
if list:
yield each in gen(list[1:])