I have a text file which has multiple sections which are demarcated with a particular string. In the code so far, this section has been extracted as a list of separate lines.
The original file looks something like this:
>>
1. Title
Some data
Some data
Some data
>>
2. Title
Some data
Some data
Some data
>>
3. Title
Some data
Some data
Some data
This is represented in a list several strings as I mentioned, so:
['>>', '1. Title', 'Some data, 'Some data', 'Some data', '>>', '2. Title', ... ]
What is the easiest way to subset this list in to separate entries as demarcated by the >>
? There can be an arbitrary number of entries and they can differ in length, so using simple slicing notation isn't an option as far as I can work out - it has to depend on the demarcation within the list.
I'd like to end up with:
Entry 1:
['>>', '1. Title', 'Some data', 'Some data', 'Some data']
Entry 2:
['>>', '2. Title', 'Some data', 'Some data', 'Some data']
Entry 3:
['>>', '3. Title', 'Some data', 'Some data', 'Some data']
(I'm not actually concerned about collecting the >>
once the lists are separated if that makes any difference.)