flatten a nested list python code example
Example 1: flatten a list of list python
import itertools
list_of_list = [[1, 2, 3], [4, 5], [6]]
chain = itertools.chain(*images)
flattened_list = list(chain)
Example 2: python nested list
my_list = [[1, 2], ["one", "two"]]
my_list[1][0]
Example 3: python nested list
L = [[1, 2, 3],[4, 5, 6],[7, 8, 9]]
for list in L:
for number in list:
print(number, end=' ')
Example 4: flatten lists python
flat_list = []
for sublist in l:
for item in sublist:
flat_list.append(item)