MCPcopy Index your code
hub / github.com/RustPython/RustPython / ratio

Method ratio

Lib/difflib.py:597–620  ·  view source on GitHub ↗

Return a measure of the sequences' similarity (float in [0,1]). Where T is the total number of elements in both sequences, and M is the number of matches, this is 2.0*M / T. Note that this is 1 if the sequences are identical, and 0 if they have nothing in common.

(self)

Source from the content-addressed store, hash-verified

595 yield group
596
597 def ratio(self):
598 """Return a measure of the sequences' similarity (float in [0,1]).
599
600 Where T is the total number of elements in both sequences, and
601 M is the number of matches, this is 2.0*M / T.
602 Note that this is 1 if the sequences are identical, and 0 if
603 they have nothing in common.
604
605 .ratio() is expensive to compute if you haven't already computed
606 .get_matching_blocks() or .get_opcodes(), in which case you may
607 want to try .quick_ratio() or .real_quick_ratio() first to get an
608 upper bound.
609
610 >>> s = SequenceMatcher(None, "abcd", "bcde")
611 >>> s.ratio()
612 0.75
613 >>> s.quick_ratio()
614 0.75
615 >>> s.real_quick_ratio()
616 1.0
617 """
618
619 matches = sum(triple[-1] for triple in self.get_matching_blocks())
620 return _calculate_ratio(matches, len(self.a) + len(self.b))
621
622 def quick_ratio(self):
623 """Return an upper bound on ratio() relatively quickly.

Callers 5

get_close_matchesFunction · 0.95
test_one_insertMethod · 0.95
test_one_deleteMethod · 0.95

Calls 4

get_matching_blocksMethod · 0.95
_calculate_ratioFunction · 0.85
lenFunction · 0.85
sumFunction · 0.50

Tested by 4

test_one_insertMethod · 0.76
test_one_deleteMethod · 0.76