Write a program that prints every given list flattened. For example, flattened is , and flattened is .
Define and use a recursive function
flatten(t)
that flattens a list .
Using the @ast@ package, you can extract the list encoded in a string with @t = ast.literal_eval(s)@.
The input consists of several lists.
Print every given list flattened.
Input
[] ['a'] [['a']] [[['a']]] ['a', 'b'] ['a', []] [[], 'a'] [['a'], 'b'] ['a', ['b']] [[['a']], 'b'] ['a', [['b']]] [['a', 'b'], ['c', 'd']]
Output
[] ['a'] ['a'] ['a'] ['a', 'b'] ['a'] ['a'] ['a', 'b'] ['a', 'b'] ['a', 'b'] ['a', 'b'] ['a', 'b', 'c', 'd']