20Flatten a Nested List

    Mediumrecursionlists

    Write flatten(items) that takes a list which may contain other lists (nested to any depth) and returns a single flat list of all the non-list values, in order.

    Examples

    Example 1
    >>> flatten([1, [2, 3], [4, [5, 6]]])
    [1, 2, 3, 4, 5, 6]
    Example 2
    >>> flatten([[['deep']]])
    ['deep']

    Run examples checks the 2 examples above. Submit runs all 6 tests, including hidden edge cases, and marks the challenge solved.

    solution.py
    Loading Python…

    Test results show up here

    Write flatten in the editor, then run the examples. Use print() freely: its output is shown for each test.