how to split this kind of text into sections
Jussi Piitulainen
jpiitula at ling.helsinki.fi
Fri Apr 25 11:17:09 EDT 2014
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 each line as a unit? You could group
lines straight from some file object using itertools.groupby and then
''.join each group.
(It's \n and \r, and \r\n when they are both there, but you can just
let Python read the lines.)
More information about the Python-list
mailing list