convert list of strings to set of regexes; convert list of strings to trie

Matteo Dell'Amico della at toglimi.linux.it
Tue Jul 20 17:45:08 CEST 2004


Klaus Neuner wrote:
> Hello,
> 
> I need a function that converts a list into a set of regexes. Like so:
> 
>   string_list = ["blaa", "blab", "raaa", "rabb"]
> 
>   print string_list2regexes(string_list)
> 
> 
> This should return something like:
> 
>   ["bla(a|b)", "ra(aa|bb)"]

So, I guess you just want to isolate common prefixes.

> I am aware of the fact that converting the list to a *trie* would almost do
> the job. But I couldn't find anything about Python modules that produce tries.

Maybe 
http://cvs.bioperl.org/cgi-bin/viewcvs/viewcvs.cgi/biopython/Bio/triefind.py?annotate=1.1&cvsroot=biopython 
can be of some use for you, even if I didn't have a look at it.

-- 
Ciao,
Matteo



More information about the Python-list mailing list