code: def dictionary_values_to_lists(
      hyperparameter_dict, hyperparameters_list_type=None
  ):
      """Given a dictionary, returns a copy whose values are
       either lists, distributions with a ``rvs`` method, or None.
  
      The output is suitable for hyperparameter grid search.
  
      Does this by converting values that do not conform into
      singleton elements inside a list.
  
      Parameters
      ----------
      hyperparameter_dict : `dict` [`str`, `any`]
          Dictionary of hyperparameters.
  
      hyperparameters_list_type : `set` [`str`] or `dict` [`str`, `list`] or None, optional, default None
          Hyperparameters that must be a `list` or other recognized value.
          e.g. ``regressor_cols`` is `list` or None, ``holiday_lookup_countries`` is `list` or "auto"
          or None.
  
          Thus, a flat list must become nested. E.g. ["US", "UK"] must be converted to [["US", "UK"]].
  
          Specifically, the values in ``hyperparameter_dict`` must be of type
          `list` [`list` or other accepted value].
  
              * If a set, other accepted value = [None]
              * If a dict, other accepted value is specified by the key's value, a
                list of valid options.
  
                For example, to allow `list` or "auto" or None, use
                ``hyperparameters_list_type={"regressor_cols": [None, "auto"]}``.
  
                For example, ``hyperparameters_list_type={"regressor_cols": [None]}`` is equivalent to
                ``hyperparameters_list_type={"regressor_cols"}`` using the set specification.
  
      Notes
      -----
      These values are unchanged:
  
          * [None]
          * ["value1", "value2"]
          * [[1, 2], [3, 4]]
          * [[1], None, [3]]
          * scipy.stats.expon(scale=.1)
  
      These values are put in a list:
  
          * None
          * 1
          * np.array([1, 2, 3])
          * {"k": "v"}
  
      These values are put in a list if their key is
      in ``hyperparameters_list_type`` and the other
      acceptable value is [None], otherwise unchanged:
          * []
          * [1, 2, 3]
          * (1, 2, 3)
          * ["value1", "value2"]
  
      Raises
      ------
      ValueError
          If a key is in ``hyperparameters_list_type`` but
          its value is not a list, tuple, or None.
  
      Returns
      -------
      hyperparameter_grid : `dict` [`str`, `list` [`any`] or distribution with ``rvs`` method]
          A dictionary suitable to pass as ``param_distributions`` to
          `sklearn.model_selection.RandomizedSearchCV` for grid search.
  
          As explained in `sklearn.model_selection.RandomizedSearchCV`:
          Dictionary with parameters names (string) as keys and distributions
          or lists of parameters to try. Distributions must provide a ``rvs``
          method for sampling (such as those from scipy.stats.distributions).
          If a list is given, it is sampled uniformly.
      """
      hyperparameter_grid = hyperparameter_dict.copy()
      if hyperparameters_list_type is None:
          hyperparameters_list_type = {}
  
      for param, value in hyperparameter_dict.items():
          # Distribution is allowed
          is_distribution = hasattr(value, "rvs")
          is_list = isinstance(value, (list, tuple))
  
          if param in hyperparameters_list_type:
              if isinstance(hyperparameters_list_type, dict):
                  recognized_values = hyperparameters_list_type.get(
                      param, [None]
                  )
              else:
                  recognized_values = [None]
  
              if is_list:
                  # A list is provided
                  if len(value) == 0 or not all(
                      [
                          isinstance(list_item, (list, tuple))
                          or list_item in recognized_values
                          for list_item in value
                      ]
                  ):
                      # Not all its values are acceptable for the hyperparameter,
                      # therefore enclose the value in a list.
                      hyperparameter_grid[param] = [value]
              elif value in recognized_values:
                  # Not a list, but the value is acceptable
                  hyperparameter_grid[param] = [value]
              else:
                  raise ValueError(
                      f"The value for {param} must be a list, tuple, or one of {recognized_values}, "
                      f"found {value}."
                  )
  
          else:
              # Any list or distribution is allowed.
              # Violating elements are enclosed the value in a list
              if not is_list and not is_distribution:
                  hyperparameter_grid[param] = [value]
  
      return hyperparameter_grid
  
imports: import copy
  import dataclasses
  import functools
  import math
  import re
  import warnings
  from dataclasses import field
  from typing import List
  import numpy
  import pandas
  from pandas.testing import assert_frame_equal
  from pandas.testing import assert_index_equal
  from pandas.testing import assert_series_equal
label_desc: Use image node_id 7 for calling a global function with example usage: dictionary_values_to_lists(hyperparameter_dict, hyperparameters_list_type) and returns: hyperparameter_grid