Python ProgrammingPython Programming

How to make a flat list out of a list of lists?

import more_itertools

thelist = [[1, 2, 3], [[4, 5, 6]], [7], 8, 9]
flatlist = list(more_itertools.collapse(thelist))
print(flatlist)

thelist = [[1, 2, 3], [[4, 5, 6]], [[[7, 8, 9]]]]
flatlist = list(more_itertools.collapse(thelist))
print(flatlist)
Output
[1, 2, 3, 4, 5, 6, 7, 8, 9]
[1, 2, 3, 4, 5, 6, 7, 8, 9]