I’m looking for a Python library for finding the longest common sub-string from a set of strings. There are two ways to solve this problem:
- using suffix trees
- using dynamic programming.
Method implemented is not important. It is important it can be used for a set of strings (not only two strings).
These paired functions will find the longest common string in any arbitrary array of strings:
No doubt the algorithm could be improved and I’ve not had a lot of exposure to Python, so maybe it could be more efficient syntactically as well, but it should do the job.
EDIT: in-lined the second is_substr function as demonstrated by J.F. Sebastian. Usage remains the same. Note: no change to algorithm.
Hope this helps,
Jason.