It is generators today. I saw a question today that wanted to find a way to flatten a list recursively without using loops and imports. tobias_k answered it with a following code:
def flatten(test_list):
if isinstance(test_list, list):
if len(test_list) == 0:
return []
first, rest = test_list[0], test_list[1:]
return flatten(first) + flatten(rest)
else:
return [test_list]
Is there a way of creating a generator (with keeping the rules: no imports,loops)?
NOTE: it is purely educational. i know it is not the best idea, but coulnd't figure out how to do it.