I've implemented the exact same functionality with recursions, I also want a version without recursion as Python has a recursion limit and there are problems while sharing data.
sublist2 = [{'nothing': "Notice This"}]
sublist1 = [{'include':[sublist2]}]
mainlist = [{'nothing': 1}, {'include':[sublist1, sublist2]},
{'nothing': 2}, {'include':[sublist2]}]
What is to be filled in the Todo?
for i in mainlist:
if 'nothing' in i:
# Do nothing
else if 'include' in i:
# Todo
# Append the contents of the list mentioned recursively
# in it's own place without disrupting the flow
After the operation the expected result
mainlist = [{'nothing': 1},
{'nothing': "Notice This"}, {'nothing': "Notice This"},
{'nothing':2},
{'nothing': "Notice This"}]
If you notice sublist1 references to sublist2. That's the reason
{'include':[sublist1, sublist2]} is replaced by
{'nothing':"Notice This"}, {'nothing':"Notice This"}
I've tried the following
Inserting values into specific locations in a list in Python