LCS algorithm

Drazen Gemic dgemic at nospam.net
Sat Nov 9 10:20:16 EST 2002


Alex Martelli wrote:
> Drazen Gemic wrote:
> 
> 
>>Is there an implementation of Largest Common Sequence algorithm
>>in Python ? I am particulary interested in implementation that
>>works for character strings.
> 
> 
> difflib.py in the standard python library contains that, as well
> as much else besides.
> 
> 
>>>>import difflib
>>>>sm = difflib.SequenceMatcher()
>>>>a = 'One by one the guests arrive'
>>>>b = 'The guests are coming through'
>>>>sm.set_seqs(a, b)
>>>>sm.find_longest_match(0, len(a), 0, len(b))
>>>
> (12, 1, 12)
> 
>>>>a[12:12+12]
>>>
> 'he guests ar'
> 
>>>>b[1:1+12]
>>>
> 'he guests ar'
> 
> 
> 
> Alex
> 

Thank you, you have done a great favour to me.

                           DG




More information about the Python-list mailing list