All problems
Nested List Flatten
Problem
Flatten a nested list of integers into a single list of integers.
nested is a list whose elements are either integers or other nested lists. Flatten depth-first, preserving the left-to-right order.
Return the flat list.
Hint
Recurse when the element is a list and append otherwise.
Test cases
case 1
in: [[1,[2,3],4]]
expected: [1,2,3,4]
case 2
in: [[]]
expected: []
case 3
in: [[[1,2],[3,[4,5]]]]
expected: [1,2,3,4,5]
case 4
in: [[[[]]]]
expected: []
Starter codePython
def flatten_nested(nested):
# Your code here
pass4 test cases · run your code against them in the editor