code: def _closest_patterns(self, patterns: List[str], scansion: str) -> List[str]:
          
          pattern = scansion.replace(" ", "")
          pattern = pattern.replace(self.constants.FOOT_SEPARATOR, "")
          ending = pattern[-1]
          candidate = pattern[:len(pattern) - 1] + self.constants.OPTIONAL_ENDING
          cans = [(distance(candidate, x), x) for x in patterns
                  if len(x) == len(candidate)]
          if cans:
              cans = sorted(cans, key=lambda tup: tup[0])
              top = cans[0][0]
              return [can[1][:-1] + ending for can in cans if can[0] == top]
          return []
docs: Find the closest group of matching valid patterns.
  
          :patterns: a list of patterns
          :scansion: the scansion pattern thus far
          :return: list of the closest valid patterns; only candidates with a matching
          length/number of syllables are considered.