import re


def isolate_titles(targets, predictions):
  """Maps each target and prediction to a list of movies metioned.

  Args:
    targets: a list of strings, the target from the validation set
    predictions: a list of strings, the model predictions

  Returns:
    a tuple containing a list of lists for both target and prediction titles
  """
  all_target_titles = []
  all_prediction_titles = []
  for tar, pred in zip(targets, predictions):
    target_titles = re.findall(r"\@([^@]*\([^@]*\)[^@]*)\@", tar)
    prediction_titles = re.findall(r"\@([^@]*\([^@]*\)[^@]*)\@", pred)
    all_target_titles.append([x.strip() for x in target_titles])
    all_prediction_titles.append([x.strip() for x in prediction_titles])
  return all_target_titles, all_prediction_titles