I already know lots of methods using which you can flatten list of lists.
For example :
Method 1:
A = [[1, 2], [3, 4], [5, 6]]
print sum(A, [])
Method 2
from itertools import chain
print list((chain.from_iterable(A)))
Method 3
print [ val for sublist in A for val in sublist ]
But if your list are arranged in this way:
[[[[[[3]]]]], 'i', 1, 2] -> [3, 'i', 1, 2]
[[[[2]]], 1] -> [2, 1]
[[[[3]]], [[[2]]], [[[2]]], [[['y']]]] -> [3, 2, 2, 'y']
Nesting of lists can be of any depth. Could you help me here?
My idea is to use the type
function in Python with something like
A = [[[[[[[3]]]]]]]
var = type(A)
while type(A) == var and type(A[0]) == var:
A = A[0]
print A