aligning text with space-normalized text

Steven Bethard steven.bethard at gmail.com
Fri Jul 1 13:38:49 EDT 2005


Peter Otten wrote:
> import re
> _reLump = re.compile(r"\S+")
> 
> def indices(text, chunks):
>     lumps = _reLump.finditer(text)
>     for chunk in chunks:
>         lump = [lumps.next() for _ in chunk.split()]
>         yield lump[0].start(), lump[-1].end()

Thanks, that's a really nice, clean solution!

STeVe



More information about the Python-list mailing list