Implementation
list_of_lists = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
flat_list = [item for sublist in list_of_lists for item in sublist]
print(flat_list)
# [1, 2, 3, 4, 5, 6, 7, 8, 9]
Add if statement
list_of_lists = [[1, 2, 3], None, [4, 5, None], [6, None, 7], None, [8, 9]]
flat_list = [
item for sublist in list_of_lists if sublist is not None for item in sublist if item is not None
]
print(flat_list)
# [1, 2, 3, 4, 5, 6, 7, 8, 9]