code: def _validate_legend_loc(loc):
      """
      Confirm that loc is a type which rc.Params["legend.loc"] supports.
  
      .. versionadded:: 3.8
  
      Parameters
      ----------
      loc : str | int | (float, float) | str((float, float))
          The location of the legend.
  
      Returns
      -------
      loc : str | int | (float, float) or raise ValueError exception
          The location of the legend.
      """
      if isinstance(loc, str):
          try:
              return _validate_named_legend_loc(loc)
          except ValueError:
              pass
          try:
              loc = ast.literal_eval(loc)
          except (SyntaxError, ValueError):
              pass
      if isinstance(loc, int):
          if 0 <= loc <= 10:
              return loc
      if isinstance(loc, tuple):
          if len(loc) == 2 and all(isinstance(e, Real) for e in loc):
              return loc
      raise ValueError(f"{loc} is not a valid legend location.")
  
imports: import ast
  from functools import lru_cache, reduce
  from numbers import Real
  import operator
  import os
  import re
  import numpy
  from matplotlib import _api, cbook
  from matplotlib.cbook import ls_mapper
  from matplotlib.colors import Colormap, is_color_like
  from matplotlib._fontconfig_pattern import parse_fontconfig_pattern
  from matplotlib._enums import JoinStyle, CapStyle
  from cycler import Cycler, cycler
label_desc: Use image node_id 39 for calling a global function with example usage: _validate_legend_loc(loc) and returns: _validate_named_legend_loc, loc, loc