Having this list
l = [['a', 'b', 'c', 'd'],[[["d","d"]],['z', 'x', 'g', 'd'], ['z', 'C', 'G', 'd']]]
I would like to get a function extracting all nested lists and return
l = [['a', 'b', 'c', 'd'],["d","d"],['z', 'x', 'g', 'd'], ['z', 'C', 'G', 'd']]
like flatten but keeping the list formation of every nested list. This is the closest I have been and I feel like there is a way of accomplishing my goal without using an extra structure to filter duplicates. Also, order matters in string and list level.
def get_all_nested_list(l,returned_list):
nested_list = l
while isinstance(nested_list, list):
for elem in nested_list:
get_all_nested_list(elem,returned_list)
if isinstance(nested_list[0], str):
returned_list.append(nested_list)
nested_list = nested_list[0]
if __name__ == '__main__':
l = [['a', 'b', 'c', 'd'],[[["d","d"]],['z', 'x', 'g', 'd'], ['z', 'C', 'G', 'd']]]
l2 = []
get_all_nested_list(l,l2)
print(l2)
Any other ways of doing it the above either by using itertools or suggesting an actually proper way of using yield instead of passing another list as argument are more than welcome.