Does my RE rock, or suck?

Bryan Olson fakeaddress at nowhere.org
Fri Jul 9 22:06:26 EDT 2004


Pierre-Frédéric Caillaud wrote:

 >
 >     I think you need some binary search or some form of tree here.
 >
 >     Make a list of prefixes, sort them, store this list somewhere it's
 > quick  to access.
 >     It is then very quick (N log N) to look in that list which key
 > corresponds to the beginning of a path.
 >     Basically you do a bisection search and, of course you don't have
 > an  exact match but the last key you end up on is your prefix.

That doesn't quite work for my problem.  Consider the list:

     'John',
     'Johnson',
     'Jones'

A search for the string 'Johnston' (note the 't') will locate
the point between 'Johnson' and 'Jones'.  'Johnson' shares a
long prefix with 'Johnston', but I want the longest string in
the list that *is* a prefix of 'Johnston', and in this case that
is 'John'.


-- 
--Bryan



More information about the Python-list mailing list