I have a nested list to flatten:
L = [[1, 0, 0], 23, 30, [1, 1, 0], [1, 1]]
I used two approaches but none of them worked:
First:
flattened_list = []
for x in L:
for y in x:
flattened_list.append(y)
Error:
'int' object is not iterable
Second (list comprehension):
[y for x in L for y in x]
Error:
'int' object is not iterable
UPDATE This question is somewhat different because 23 and 30 are not in lists. If I do
L = [[1, 0, 0], [23], [30], [1, 1, 0], [1, 1]]
Then the following works:
merged = list(itertools.chain(*L))
[1, 0, 0, 23, 30, 1, 1, 0, 1, 1]