testing a sequence for 'identicalness'

Emile van Sebille emile at fenx.com
Thu Jul 4 13:54:56 EDT 2002


Rajarshi Guha
> 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)
>

You could do something like:
>>> def isclose(list): return map(round,list)
...

>>> l1 = [1]*10
>>> l2 = [.9, 1,1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7]
>>> s = difflib.SequenceMatcher(None, isclose(l1),isclose(l2))
>>> s.ratio()
0.69999999999999996

which might do it for an appropriate isclose()


--

Emile van Sebille
emile at fenx.com

---------




More information about the Python-list mailing list