testing a sequence for 'identicalness'

Rajarshi Guha rajarshi at presidency.com
Thu Jul 4 13:02:29 EDT 2002


On Thu, 04 Jul 2002 12:43:23 -0400, Emile van Sebille wrote:

> 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

Thanks! Did'nt know about this module.
OK - what if I allow numbers like 1.1 and 1 to be equal (that is numbers
which are close are also consdiered to be identical)

I'm not really clear on how to set this up in difflib - maybe the bagging
idea is a better choice for this problem?

TIA,



More information about the Python-list mailing list