pyflat Flatten a list like Array.flat() in other languages print(flatten([1, 2, [3, 4], 5])) # [1, 2, 3, 4, 5] print(flatten([1, [2, [3, [4, 5]]]])) # [1, 2, [3, [4, 5]]]