Yes, here's one way to do it:
def flatten(lst):
for elem in lst:
if type(elem) in (tuple, list):
for i in flatten(elem):
yield i
else:
yield elem
Please note, this creates a generator, so if you need a list, wrap it in list()
:
flattenedList = list(flatten(nestedList))