Inspired Python
◆◆◆
def flatten(l):
match l:
case (list() | tuple() | set()) as items:
for item in items:
yield from flatten(item)
case _:
yield l
>>> list(flatten([[1, 2], {"site": "inspiredpython.com"},
"Inspired Python", [3, [4], [5, (6, (7, 8))]]]))
[1, 2, {'site': 'inspiredpython.com'}, 'Inspired Python', 3, 4, 5, 6, 7, 8]