code: def best_match(errors, key=relevance):
      """
      Try to find an error that appears to be the best match among given errors.
  
      In general, errors that are higher up in the instance (i.e. for which
      `ValidationError.path` is shorter) are considered better matches,
      since they indicate "more" is wrong with the instance.
  
      If the resulting match is either :validator:`oneOf` or :validator:`anyOf`,
      the *opposite* assumption is made -- i.e. the deepest error is picked,
      since these validators only need to match once, and any other errors may
      not be relevant.
  
      Arguments:
          errors (collections.Iterable):
  
              the errors to select from. Do not provide a mixture of
              errors from different validation attempts (i.e. from
              different instances or schemas), since it won't produce
              sensical output.
  
          key (collections.Callable):
  
              the key to use when sorting errors. See `relevance` and
              transitively `by_relevance` for more details (the default is
              to sort with the defaults of that function). Changing the
              default is only useful if you want to change the function
              that rates errors but still want the error context descent
              done by this function.
  
      Returns:
          the best matching error, or ``None`` if the iterable was empty
  
      .. note::
  
          This function is a heuristic. Its return value may change for a given
          set of inputs from version to version if better heuristics are added.
      """
      errors = iter(errors)
      best = next(errors, None)
      if best is None:
          return
      best = max(itertools.chain([best], errors), key=key)
  
      while best.context:
          best = min(best.context, key=key)
      return best
  
imports: from collections import defaultdict, deque
  import itertools
  import pprint
  import textwrap
  import attr
  from jsonschema import _utils
  from jsonschema.compat import PY3, iteritems
label_desc: Use image node_id 2 for calling a global function with example usage: best_match(errors, key) and returns: best