class_docstr: SequenceMatcher is a flexible class for comparing pairs of sequences of
  any type, so long as the sequence elements are hashable.  The basic
  algorithm predates, and is a little fancier than, an algorithm
  published in the late 1980's by Ratcliff and Obershelp under the
  hyperbolic name "gestalt pattern matching".  The basic idea is to find
  the longest contiguous matching subsequence that contains no "junk"
  elements (R-O doesn't address junk).  The same idea is then applied
  recursively to the pieces of the sequences to the left and to the right
  of the matching subsequence.  This does not yield minimal edit
  sequences, but does tend to yield matches that "look right" to people.
  
  SequenceMatcher tries to compute a "human-friendly diff" between two
  sequences.  Unlike e.g. UNIX(tm) diff, the fundamental notion is the
  longest *contiguous* & junk-free matching subsequence.  That's what
  catches peoples' eyes.  The Windows(tm) windiff has another interesting
  notion, pairing up elements that appear uniquely in each sequence.
  That, and the method here, appear to yield more intuitive difference
  reports than does diff.  This method appears to be the least vulnerable
  to syncing up on blocks of "junk lines", though (like blank lines in
  ordinary text files, or maybe "<P>" lines in HTML files).  That may be
  because this is the only method of the 3 that has a *concept* of
  "junk" <wink>.
  
  Example, comparing two strings, and considering blanks to be "junk":
  
  >>> s = SequenceMatcher(lambda x: x == " ",
  ...                     "private Thread currentThread;",
  ...                     "private volatile Thread currentThread;")
  >>>
  
  .ratio() returns a float in [0, 1], measuring the "similarity" of the
  sequences.  As a rule of thumb, a .ratio() value over 0.6 means the
  sequences are close matches:
  
  >>> print(round(s.ratio(), 3))
  0.866
  >>>
  
  If you're only interested in where the sequences match,
  .get_matching_blocks() is handy:
  
  >>> for block in s.get_matching_blocks():
  ...     print("a[%d] and b[%d] match for %d elements" % block)
  a[0] and b[0] match for 8 elements
  a[8] and b[17] match for 21 elements
  a[29] and b[38] match for 0 elements
  
  Note that the last tuple returned by .get_matching_blocks() is always a
  dummy, (len(a), len(b), 0), and this is the only case in which the last
  tuple element (number of elements matched) is 0.
  
  If you want to know how to change the first sequence into the second,
  use .get_opcodes():
  
  >>> for opcode in s.get_opcodes():
  ...     print("%6s a[%d:%d] b[%d:%d]" % opcode)
   equal a[0:8] b[0:8]
  insert a[8:8] b[8:17]
   equal a[8:29] b[17:38]
  
  See the Differ class for a fancy human-friendly file differencer, which
  uses SequenceMatcher both to compare sequences of lines, and to compare
  sequences of characters within similar (near-matching) lines.
  
  See also function get_close_matches() in this module, which shows how
  simple code building on SequenceMatcher can be used to do useful work.
  
  Timing:  Basic R-O is cubic time worst case and quadratic time expected
  case.  SequenceMatcher is quadratic time for the worst case and has
  expected-case behavior dependent in a complicated way on how many
  elements the sequences have in common; best case time is linear.
docstr: Return list of triples describing matching subsequences.
  
  Each triple is of the form (i, j, n), and means that
  a[i:i+n] == b[j:j+n].  The triples are monotonically increasing in
  i and in j.  New in Python 2.5, it's also guaranteed that if
  (i, j, n) and (i', j', n') are adjacent triples in the list, and
  the second is not the last triple in the list, then i+n != i' or
  j+n != j'.  IOW, adjacent triples never describe adjacent equal
  blocks.
  
  The last triple is a dummy, (len(a), len(b), 0), and is the only
  triple with n==0.
  
  >>> s = SequenceMatcher(None, "abxcd", "abcd")
  >>> list(s.get_matching_blocks())
  [Match(a=0, b=0, size=2), Match(a=3, b=2, size=2), Match(a=5, b=4, size=0)]
docstr_tok: ["Return","list","of","triples","describing","matching","subsequences",".","Each","triple","is","of","the","form","(","i",",","j",",","n",")",",","and","means","that","a","[","i",":","i+n","]","==","b","[","j",":","j+n","]",".","The","triples","are","monotonically","increasing","in","i","and","in","j",".","New","in","Python","2.5",",","it","'s","also","guaranteed","that","if","(","i",",","j",",","n",")","and","(","i","'",",","j","'",",","n","'",")","are","adjacent","triples","in","the","list",",","and","the","second","is","not","the","last","triple","in","the","list",",","then","i+n","!","=","i","'","or","j+n","!","=","j","'",".","IOW",",","adjacent","triples","never","describe","adjacent","equal","blocks",".","The","last","triple","is","a","dummy",",","(","len","(","a",")",",","len","(","b",")",",","0",")",",","and","is","the","only","triple","with","n==0",".",">",">",">","s","=","SequenceMatcher","(","None",",","``","abxcd","''",",","``","abcd","''",")",">",">",">","list","(","s.get_matching_blocks","(",")",")","[","Match","(","a=0",",","b=0",",","size=2",")",",","Match","(","a=3",",","b=2",",","size=2",")",",","Match","(","a=5",",","b=4",",","size=0",")","]"]
code: def get_matching_blocks(self):
      """Return list of triples describing matching subsequences.
  
      Each triple is of the form (i, j, n), and means that
      a[i:i+n] == b[j:j+n].  The triples are monotonically increasing in
      i and in j.  New in Python 2.5, it's also guaranteed that if
      (i, j, n) and (i', j', n') are adjacent triples in the list, and
      the second is not the last triple in the list, then i+n != i' or
      j+n != j'.  IOW, adjacent triples never describe adjacent equal
      blocks.
  
      The last triple is a dummy, (len(a), len(b), 0), and is the only
      triple with n==0.
  
      >>> s = SequenceMatcher(None, "abxcd", "abcd")
      >>> list(s.get_matching_blocks())
      [Match(a=0, b=0, size=2), Match(a=3, b=2, size=2), Match(a=5, b=4, size=0)]
      """
  
      if self.matching_blocks is not None:
          return self.matching_blocks
      la, lb = len(self.a), len(self.b)
  
      # This is most naturally expressed as a recursive algorithm, but
      # at least one user bumped into extreme use cases that exceeded
      # the recursion limit on their box.  So, now we maintain a list
      # ('queue`) of blocks we still need to look at, and append partial
      # results to `matching_blocks` in a loop; the matches are sorted
      # at the end.
      queue = [(0, la, 0, lb)]
      matching_blocks = []
      while queue:
          alo, ahi, blo, bhi = queue.pop()
          i, j, k = x = self.find_longest_match(alo, ahi, blo, bhi)
          # a[alo:i] vs b[blo:j] unknown
          # a[i:i+k] same as b[j:j+k]
          # a[i+k:ahi] vs b[j+k:bhi] unknown
          if k:  # if k is 0, there was no matching block
              matching_blocks.append(x)
              if alo < i and blo < j:
                  queue.append((alo, i, blo, j))
              if i + k < ahi and j + k < bhi:
                  queue.append((i + k, ahi, j + k, bhi))
      matching_blocks.sort()
  
      # It's possible that we have adjacent equal blocks in the
      # matching_blocks list now.  Starting with 2.5, this code was added
      # to collapse them.
      i1 = j1 = k1 = 0
      non_adjacent = []
      for i2, j2, k2 in matching_blocks:
          # Is this block adjacent to i1, j1, k1?
          if i1 + k1 == i2 and j1 + k1 == j2:
              # Yes, so collapse them -- this just increases the length of
              # the first block by the length of the second, and the first
              # block so lengthened remains the block to compare against.
              k1 += k2
          else:
              # Not adjacent.  Remember the first block (k1==0 means it's
              # the dummy we started with), and make the second block the
              # new block to compare against.
              if k1:
                  non_adjacent.append((i1, j1, k1))
              i1, j1, k1 = i2, j2, k2
      if k1:
          non_adjacent.append((i1, j1, k1))
  
      non_adjacent.append((la, lb, 0))
      self.matching_blocks = list(map(Match._make, non_adjacent))
      return self.matching_blocks
  
imports: from heapq import nlargest
  from collections import namedtuple
  from types import GenericAlias
  import re
label_desc: Use image node_id 7 for calling the SequenceMatcher obj's underlying member method code with example usage: obj.get_matching_blocks() and returns: self, self