Match beginning of two strings

Christos TZOTZIOY Georgiou tzot at
Wed Aug 6 20:54:17 CEST 2003

On Sat, 02 Aug 2003 17:39:26 -0400, rumours say that Ravi
<rxs141 at> might have written:

>I have about 200GB of data that I need to go through and extract the 
>common first part of a line. Something like this.

If you know in advance that many of these comparisons will involve large
strings, you might improve your apps' response time by using the
os.path.commonprefix function modified as proposed in

which is O(logN)-ish instead of O(N).  This patch was sent by me, but
there is a suggestion by another SF user which seems to be efficient too
(never benchmarked it against mine).
TZOTZIOY, I speak England very best,
Microsoft Security Alert: the Matrix began as open source.

More information about the Python-list mailing list