I have multiple lists of lists where the dimensions of each vary, for example
list_1 = [[1,2], [3,4,5], [6], [7,8,9,10,11,12]]
.
.
.
list_n = [[1,2,3], [4,5]]
For each of the lists above, I am looking to make flat lists, such as
list_1 = [1,2,3,4,5,6,7,8,9,10,11,12]
list_n = [1,2,3,4,5]
I have seen another stackoverflow answer Making a flat list out of list of lists in Python which works for 2D lists, but I may have many more dimensions in my lists.
Is mechanically looping through each list the best way of doing this, with use of isinstance(element, list) to check if lists still exist in the list of lists?
Or is there a elegant solution that would work on lists of any dimension?