[Tutor] Algorithm for sequence matching

Steven D'Aprano steve at pearwood.info
Sun Jul 3 03:58:37 CEST 2011


ANKUR AGGARWAL wrote:
> Hey
> I am looking for an algo for the largest sequence search in the two list.
> 
> Example : list a accepts some say 'm' numbers. list b accept says 'n'
> numbers. I want to look for the largest same sequence between the two list
> and then display it. I tried out but failed to do so.

Google is your friend. Please search for "longest common subsequence" 
and "longest common substring". You can add "algorithm" and "python" if 
you like. Wikipedia, for example, gives good algorithms for both 
problems, which can be adapted to Python.

You might also like to look at the difflib module in the standard 
library, particularly the SequenceMatcher class.


-- 
Steven


More information about the Tutor mailing list