I am trying to understand this code for flattening list:
def flatten(iterable):
"""Recursively iterate lists and tuples.
"""
for elm in iterable:
if isinstance(elm, (list, tuple)):
for relm in flatten(elm):
yield relm
else:
yield elm here
Source: Making a flat list out of a multi-type nested list
However I am not able to understand recursive statement and how control is flowing. Specially these two lines:
for relm in flatten(elm):
yield relm
Can I get gist of how recursive is working at every iteration, that would be a great help.
And Can we use some other approch to do this problem?