[Python-Dev] String method: longest common prefix of two strings

kent@lysator.liu.se kent@lysator.liu.se
19 Jan 2003 12:20:03 +0100

I'd like to get some feedback on a new string method which might
be useful: getting the longest common prefix of two strings.


1. First of all: YAGNI or not?

   I have an application where I could use this. I will be importing
   emails from a trouble-ticket system into another system. The body
   of a trouble ticket contains a log of actions. To find the new log
   entries, I'd like to compare the bodies of the last and next-to-last

2. Is there a need for a fast built-in operation coded in C?
   Should I use difflib instead?

3. Is s1.commonprefix(s2) OK? Or should the name be different?
   s1.longestcommonprefixwith(s2) is a bit awkward to write...

4. Should the method return the length of the common prefix instead
   of the common prefix itself?

5. Should there be a suffix version too?

I would be willing to provide the necessary patches to stringobject.c,
test_string.py and libstdtypes.tex.

/ Kent Engstr=F6m, kent@lysator.liu.se