I am trying to split a nested list into two nested lists using lists. I cannot do this without converting the internal lists to strings, which in turn destroys my ability to receive / print / manipulate values later.
I tried this:
paragraphs3 = [['Page: 2', 'Bib: Something', 'Derived: This n that'], ['Page: 3', 'Bib: Something', 'Argument: Wouldn't you like to know?'], ...]
derived = [k for k in paragraphs3 if 'Derived:' in k]
therest = [k for k in paragraphs3 if 'Derived:' not in k]
What happens is that all paragraphs 3 = [] end in a state of rest = [], unless I do something like this:
for i in paragraphs3:
i = str(i)
paragraphs4.append(i)
If I then pass paragraphs 4 to the list comprehension, I get two lists as I want. But since then they are no longer nested lists:
for i in therest:
g.write('\n'.join(i))
g.write('\n\n')
Writes down every character! in line = [] in a separate line:
'
P
a
g
e
:
2
'
So I'm looking for a better way to separate paragraphs 3 ... Or maybe the solution lies somewhere else? The end result / result I'm looking for is:
Page: 2
Bib: Something
Derived: This n that
Page: 3
Bib: Something
.
.
.