CoreChallenge 19 of 34

Flatten anything

Write flatten(nested) that turns arbitrarily nested into one flat list, preserving order. Non-list items are kept as they are.

Examples
flatten([1, [2, [3, [4]], 5]]) → [1, 2, 3, 4, 5]
Exercise

Flatten anything

4 checks
def flatten(nested):
    ...


print(flatten([1, [2, [3, [4]], 5]]))
 
Python (loads on first run)Ctrl+Enter runs
Output
Press Run to try your code, then Check answer to grade it.