I have a code as below and I need it to unpack lists using yield:
def flat_list(array):
d=[]
for i in array:
if not isinstance(i, list):
yield i
else:
flat_list(i)
For example, flat_list([1, [2, 2, 2], 4]) should return [1, 2, 2, 2, 4]. My code returns [1, 4].
I understand from previous question that I need not only recursively call a function, but to specify what it should do.
But how do you add flat_list(i) items to yield items? Something like flat_list(i).extend(yield i).
dis unused. You don't need to fill a list in your function when you yield