how to split this kind of text into sections

Terry Reedy tjreedy at udel.edu
Fri Apr 25 13:52:56 EDT 2014


On 4/25/2014 9:07 AM, oyster wrote:
> I have a long text, which should be splitted into some sections, where
> all sections have a pattern like following with different KEY.

Computers are worse at reading your mind than humans. If you can write 
rules that another person could follow, THEN we could help you translate 
the rules to Python.

If you have 1 moderate length file or a few short files, I would edit 
them by hand to remove ignore lines and put a blank line between 
sections. A program to do the rest would then be easy.

> the above text should be splitted as a LIST with 3 items, and I also
> need to know the KEY for LIST is ['I am section', 'let's continue', 'I
> am using']:

This suggests that the rule for keys is 'first 3 words of a line, with 
contractions counted as 2 words'. Correct?

Another possible rule is 'a member of the following list: ...', as you 
gave above but presumably expanded.

-- 
Terry Jan Reedy




More information about the Python-list mailing list