#K67462. Flatten a Nested List

    ID: 32648 Type: Default 1000ms 256MiB

Flatten a Nested List

Flatten a Nested List

The task is to flatten a possibly nested list of integers into a single list that preserves the original order of appearance. In other words, given a nested list (L) (which can include integers and further lists), you need to return a flat list containing all the integers in the same order as they appear when traversing (L) in a depth-first manner.

For example, if the input is [1, [2, [3, 4], 5], 6], the correct output would be [1, 2, 3, 4, 5, 6].

inputFormat

The input consists of a single line from standard input containing a nested list represented in Python list syntax. For example:
[1, [2, [3, 4], 5], 6].

outputFormat

Print the flattened list in Python list format to standard output. For example, for the above input, the expected output is [1, 2, 3, 4, 5, 6].## sample

[1, [2, [3, 4], 5], 6]
[1, 2, 3, 4, 5, 6]