Method: difflib.SequenceMatcher.ratio
Calls: 304, Exceptions: 0, Paths: 1Back
Path 1: 304 calls (1.0)
0.9444444444444444 (68) 0.972972972972973 (36) 0.43902439024390244 (36) 0.7027027027027027 (18) 0.875 (18) 0.75 (18) 0.9285714285714286 (12) 0.9090909...
1def ratio(self):
2 """Return a measure of the sequences' similarity (float in [0,1]).
3
4 Where T is the total number of elements in both sequences, and
5 M is the number of matches, this is 2.0*M / T.
6 Note that this is 1 if the sequences are identical, and 0 if
7 they have nothing in common.
8
9 .ratio() is expensive to compute if you haven't already computed
10 .get_matching_blocks() or .get_opcodes(), in which case you may
11 want to try .quick_ratio() or .real_quick_ratio() first to get an
12 upper bound.
13
14 >>> s = SequenceMatcher(None, "abcd", "bcde")
15 >>> s.ratio()
16 0.75
17 >>> s.quick_ratio()
18 0.75
19 >>> s.real_quick_ratio()
20 1.0
21 """
22
23 matches = sum(triple[-1] for triple in self.get_matching_blocks())
24 return _calculate_ratio(matches, len(self.a) + len(self.b))