The list in question may look like: [1, [1, 2], [1, [2, 3]], [1, [2, [3, 4]]]]
. The output list that I want would take that list of lists and flatten it to [1, 1, 2, 1, 2, 3, 1, 2, 3, 4]
.
I thought of using a while loop with the condition to check if there are any elements in the list that are of type list and flattening them but am having trouble coming up with an algorithm that takes care of that. Is there a way to perform what I want?