PYTHON CODING
- waclaw_koscielniak

- Jul 23
- 1 min read
def flatten(lst):
for item in lst:
if isinstance(item, list):
yield from flatten(item)
else:
yield item
print(list(flatten([1, [2, [3, 4], 5]])))
[Running] python3 -u "/Users/name/test/test101.py"
[1, 2, 3, 4, 5]
[Done] exited with code=0 in 0.052 seconds



Did you try to run it?