code: def get_user_history(train_history, valid_history, user_history_path):
      """Generate user history file.
  
      Args:
          train_history (list): Train history.
          valid_history (list): Validation history
          user_history_path (str): Path to file.
      """
      fp_user_history = open(user_history_path, "w", encoding="utf-8")
      for userid in train_history:
          fp_user_history.write(
              "train_"
              + userid
              + " "
              + ",".join(train_history[userid])
              + "\n"
          )
      for userid in valid_history:
          fp_user_history.write(
              "valid_"
              + userid
              + " "
              + ",".join(valid_history[userid])
              + "\n"
          )
      fp_user_history.close()
      if os.path.isfile(user_history_path):
          logger.info(
              f"User history file {user_history_path} successfully generated"
          )
      else:
          raise FileNotFoundError(
              f"Error when generating {user_history_path}"
          )
  
imports: import os
  import random
  import logging
  import json
  import numpy
  import re
  from tqdm import tqdm
  from nltk.tokenize import RegexpTokenizer
  from recommenders.datasets.download_utils import maybe_download, download_path, unzip_file
label_desc: Use image node_id 7 for calling a global function with example usage: get_user_history(train_history, valid_history, user_history_path) without return types