code: def correct_invalid_fifth_foot(self, scansion: str) -> str:
          
          scansion_wo_spaces = scansion.replace(" ", "")[:-1] + self.constants.OPTIONAL_ENDING
          if scansion_wo_spaces.endswith(self.constants.DACTYL +
                                         self.constants.IAMB +
                                         self.constants.OPTIONAL_ENDING):
              matches = list(re.compile
                                 (r"{}\s*{}\s*{}\s*{}\s*{}".format(
                                 self.constants.STRESSED,
                                 self.constants.UNSTRESSED,
                                 self.constants.UNSTRESSED,
                                 self.constants.UNSTRESSED,
                                 self.constants.STRESSED)).finditer(scansion))
              (start, end) = matches[len(matches) - 1].span()
              unstressed_idx = scansion.index(self.constants.UNSTRESSED, start)
              new_line = scansion[:unstressed_idx] + self.constants.STRESSED \
                         + scansion[unstressed_idx + 1:]
              return new_line
          return scansion
docs: The 'inverted amphibrach': stressed_unstressed_stressed syllable pattern is invalid
          in hexameters, so here we coerce it to stressed when it occurs at the end of a line
  
          :param scansion: the scansion pattern
          :return corrected scansion: the corrected scansion pattern
  
          >>> print(HexameterScanner().correct_invalid_fifth_foot(
          ... " -   - -   U U  -  U U U -  - U U U  - x")) # doctest: +NORMALIZE_WHITESPACE
          -   - -   U U  -  U U U -  - - U U  - x