code: def substitute_values(text, values):
      
      shift, final_text, shifts = 0, text, defaultdict(int)
      for value in values:
          first = value['old_span'][0] + shift
          second = value['old_span'][1] + shift
          new_s = value['new_surface']
          final_text = final_text[0:first] + new_s + final_text[second:]
          shift += len(new_s) - len(value['old_surface'])
          for char in range(first + 1, len(final_text)):
              shifts[char] = shift
  
      logging.debug(u'Text after numeric conversion: "%s"', final_text)
  
      return final_text, shifts
docs: Convert spelled out numbers in a given text to digits.