import copy


def expand_by_one_perturbation(original_tokenized_sentence,
                               tokenized_sentence, synonym_dict):
  """Expands given sentence by all possible synonyms.

  Note that only a single synonym replacement is applied, and it is applied
  everywhere, i.e. for every mention of the word with the synonym.
  Args:
    original_tokenized_sentence: List[str]. List of tokens.
    tokenized_sentence: List[str]. List of tokens.
    synonym_dict: dict, mapping words (str) to lists of synonyms (list of str)
  Returns:
    new_sentences_list: List[List[str]]. Outer list is across different synonym
      replacements. Inner list is over (str) tokens.
  """
  new_sentences_list = []
  for i_outer, (original_token, _) in enumerate(zip(
      original_tokenized_sentence, tokenized_sentence)):
    synonyms = synonym_dict[original_token]
    for synonym in synonyms:  # replace only one particular mention
      new_sentence = copy.copy(tokenized_sentence)
      new_sentence[i_outer] = synonym
      new_sentences_list.append(new_sentence)

  return new_sentences_list