code: def _swap_ending(s, ending, delim='_'):
      
      parts = [x for x in s.split(delim)[:-1] if x != '']
      parts.append(ending)
      return delim.join(parts)
docs: Replace the ending of a string, delimited into an arbitrary
      number of chunks by `delim`, with the ending provided
  
      Parameters
      ----------
      s       :   string
                  string to replace endings
      ending  :   string
                  string used to replace ending of `s`
      delim   :   string
                  string that splits s into one or more parts
  
      Returns
      -------
      new string where the final chunk of `s`, delimited by `delim`, is replaced
      with `ending`.