Can python read up to where a certain pattern is matched?

Andrew Bennetts andrew-pythonlist at puzzling.org
Tue Mar 9 05:37:46 CET 2004


On Mon, Mar 08, 2004 at 08:11:16PM -0800, Josiah Carlson wrote:
> >That, and I suspect that reading strings in chunks, rather than 1 byte at a
> >time, would be much faster also.
> 
> Yes and no.  string.find(character) is fast.
> 
> seq = [read_chars.find(i) for i in break_characters]
> min(filter(lambda inp:inp>-1, seq)+[-1])
> 
> May not be quite so fast for large numbers of break characters.

For finding any one of multiple characters, I expect the re module would
work well, with the bonus that it could easily extend to coping with more
complex patterns.

-Andrew.





More information about the Python-list mailing list