testing a sequence for 'identicalness'

Emile van Sebille emile at fenx.com
Thu Jul 4 12:43:23 EDT 2002


Rajarshi Guha
>   does anybody knwo how I can check a sequence for 'identical ness',
ie
> given a sequence:
>
> [1,1,1,1,1,1,1,1,1,1]
>
> it would be classified as 100% identical
>
> and
>
> [1,1,1,1,1,1,1,1,1,2]
>
> would be classified as 90% identical.


>>> import difflib
>>> l1 = [1,1,1,1,1,1,1,1,1,1]
>>> l2 = [1,1,1,1,1,1,1,1,1,2]
>>> s = difflib.SequenceMatcher(None, l1, l2)
>>> s.ratio()
0.90000000000000002

--

Emile van Sebille
emile at fenx.com

---------




More information about the Python-list mailing list