Re: how to split this kind of text into sections

2014-04-26 Thread Steven D'Aprano
On Sat, 26 Apr 2014 23:53:14 +0800, oyster wrote: > Every SECTION starts with 2 special lines; these 2 lines is special > because they have some same characters (the length is not const for > different section) at the beginning; these same characters is called the > KEY for this section. For every

Re: how to split this kind of text into sections

2014-04-26 Thread Tim Chase
On 2014-04-26 23:53, oyster wrote: > I will try to explain my situation to my best, but English is not my > native language, I don't know whether I can make it clear at last. Your follow-up reply made much more sense and your written English is far better than many native speakers'. :-) > Every S

Re: how to split this kind of text into sections

2014-04-26 Thread oyster
First of all, thank you all for your answers. I received python mail-list in a daily digest, so it is not easy for me to quote your mail separately. I will try to explain my situation to my best, but English is not my native language, I don't know whether I can make it clear at last. Every SECTIO

Re: how to split this kind of text into sections

2014-04-25 Thread Terry Reedy
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

Re: how to split this kind of text into sections

2014-04-25 Thread Steven D'Aprano
On Fri, 25 Apr 2014 09:18:22 -0400, Roy Smith wrote: > In article , > oyster wrote: >> [demo text starts] >> a line we do not need >> I am section axax >> I am section bbb, we can find that the first 2 lines of this section >> all startswith 'I am section' >> .(and here goes many other text

Re: how to split this kind of text into sections

2014-04-25 Thread Steven D'Aprano
On Fri, 25 Apr 2014 21:07:53 +0800, 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. And the > /n/r can not be used to split > > I don't know whether this can be done easily, for example by usin

Re: how to split this kind of text into sections

2014-04-25 Thread Jussi Piitulainen
oyster writes: > I have a long text, which should be splitted into some sections, where > all sections have a pattern like following with different KEY. itertools.groupby, if you know how to extract a key from a given line. > And the /n/r can not be used to split Yet you seem to want to have ea

Re: how to split this kind of text into sections

2014-04-25 Thread Tim Chase
On 2014-04-25 23:31, Chris Angelico wrote: > On Fri, Apr 25, 2014 at 11:07 PM, oyster > wrote: > > 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']: > > It's not perfectly clear, but I th

Re: how to split this kind of text into sections

2014-04-25 Thread Chris Angelico
On Fri, Apr 25, 2014 at 11:07 PM, oyster wrote: > 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']: It's not perfectly clear, but I think I have some idea of what you're trying to do. Let me re

Re: how to split this kind of text into sections

2014-04-25 Thread Roy Smith
In article , 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. And the /n/r > can not be used to split > > I don't know whether this can be done easily, for example by using RE module > > [dem

how to split this kind of text into sections

2014-04-25 Thread oyster
I have a long text, which should be splitted into some sections, where all sections have a pattern like following with different KEY. And the /n/r can not be used to split I don't know whether this can be done easily, for example by using RE module [demo text starts] a line we do not need I am se