I am trying to flatten a list using list comprehension in python. My list is somewhat like
[[1, 2, 3], [4, 5, 6], 7, 8]
just for printing
def nnl(nl): # non nested list nn = [] for x in nl: if type(x) == type(5): nn.append(x) if type(x) == type([]): n = nnl(x) for y in n: nn.append(y) return nn print (nnl([[9, 4, 5], [3, 8,[5]], 6])) # output: [9, 4, 5, 3, 8, 5, 6]