I asked a while ago about how to make a list of sublists (and of even more sublists) from a string given delimiters here.
How to process a string into layer of sublists
Now, I need to join them back together and I’m not sure how. I have tried to look here
Python : Recursively flatten a list
and
Flatten a list in python
However, neither of these answers work in my case because chain splits my string (single item “lists”) into characters, and then therefore cannot join with “\n”, and reduce does not concatenate str and list objects.
I will probably need to walk through the sublists (and their sublists) at some point. Is there a way to iterate through each level of sublist? (I can leave this as a separate question, one step at a time.. but just wondering whether this process is making sense or should I try an entire new method. I do think logically this makes the most sense, I’m just having trouble navigating it.)
Thanks.
I’m going to assume what I said in the comment is correct unless you say otherwise.
From the posts you linked, you have:
to recursively flatten an irregular list of lists, and
to create that irregular list of lists from an iterator.
The inverse of
gois justflatten(output_of_go)so the inverse ofgo(iter(string))is''.join(flatten(output_of_go)). You can see that with this test code: