I have a list of lists of lists...
A = [ [[1,3]], [[3,5], [4,4], [[5,3]]] ]
the following function outputs [1, 3, 3, 5, 4, 4, 5, 3]
def flatten(a):
b = []
for c in a:
if isinstance(c, list):
b.extend(flatten(c))
else:
b.append(c)
return b
However, I want to stop flattening on the last level so that I get [ [1,3], [3,5], [4,4], [5,3] ]