nodes: 0, module; 1, function_definition; 2, function_name:invert_dict; 3, parameters; 4, block; 5, identifier:dict_; 6, default_parameter; 7, expression_statement; 8, if_statement; 9, return_statement; 10, identifier:unique_vals; 11, True; 12, comment:"""
      Reverses the keys and values in a dictionary. Set unique_vals to False if
      the values in the dict are not unique.
  
      Args:
          dict_ (dict_): dictionary
          unique_vals (bool): if False, inverted keys are returned in a list.
  
      Returns:
          dict: inverted_dict
  
      CommandLine:
          python -m utool.util_dict --test-invert_dict
  
      Example:
          >>> # ENABLE_DOCTEST
          >>> from utool.util_dict import *  # NOQA
          >>> import utool as ut
          >>> dict_ = {'a': 1, 'b': 2}
          >>> inverted_dict = invert_dict(dict_)
          >>> result = ut.repr4(inverted_dict, nl=False)
          >>> print(result)
          {1: 'a', 2: 'b'}
  
      Example:
          >>> # ENABLE_DOCTEST
          >>> from utool.util_dict import *  # NOQA
          >>> import utool as ut
          >>> dict_ = OrderedDict([(2, 'good',), (1, 'ok',), (0, 'junk',), (None, 'UNKNOWN',)])
          >>> inverted_dict = invert_dict(dict_)
          >>> result = ut.repr4(inverted_dict, nl=False)
          >>> print(result)
          {'good': 2, 'ok': 1, 'junk': 0, 'UNKNOWN': None}
  
      Example:
          >>> # ENABLE_DOCTEST
          >>> from utool.util_dict import *  # NOQA
          >>> import utool as ut
          >>> dict_ = {'a': 1, 'b': 0, 'c': 0, 'd': 0, 'e': 0, 'f': 2}
          >>> inverted_dict = invert_dict(dict_, unique_vals=False)
          >>> inverted_dict = ut.map_dict_vals(sorted, inverted_dict)
          >>> result = ut.repr4(inverted_dict, nl=False)
          >>> print(result)
          {0: ['b', 'c', 'd', 'e'], 1: ['a'], 2: ['f']}
      """; 13, identifier:unique_vals; 14, block; 15, else_clause; 16, identifier:inverted_dict; 17, expression_statement; 18, expression_statement; 19, block; 20, assignment; 21, assignment; 22, expression_statement; 23, identifier:inverted_items; 24, list_comprehension; 25, identifier:inverted_dict; 26, call; 27, assignment; 28, tuple; 29, for_in_clause; 30, call; 31, argument_list; 32, identifier:inverted_dict; 33, call; 34, identifier:val; 35, identifier:key; 36, pattern_list; 37, call; 38, identifier:type; 39, argument_list; 40, identifier:inverted_items; 41, identifier:group_items; 42, argument_list; 43, identifier:key; 44, identifier:val; 45, attribute; 46, argument_list; 47, identifier:dict_; 48, call; 49, call; 50, identifier:six; 51, identifier:iteritems; 52, identifier:dict_; 53, attribute; 54, argument_list; 55, attribute; 56, argument_list; 57, identifier:dict_; 58, identifier:keys; 59, identifier:dict_; 60, identifier:values
code: def invert_dict(dict_, unique_vals=True):
      """
      Reverses the keys and values in a dictionary. Set unique_vals to False if
      the values in the dict are not unique.
  
      Args:
          dict_ (dict_): dictionary
          unique_vals (bool): if False, inverted keys are returned in a list.
  
      Returns:
          dict: inverted_dict
  
      CommandLine:
          python -m utool.util_dict --test-invert_dict
  
      Example:
          >>> # ENABLE_DOCTEST
          >>> from utool.util_dict import *  # NOQA
          >>> import utool as ut
          >>> dict_ = {'a': 1, 'b': 2}
          >>> inverted_dict = invert_dict(dict_)
          >>> result = ut.repr4(inverted_dict, nl=False)
          >>> print(result)
          {1: 'a', 2: 'b'}
  
      Example:
          >>> # ENABLE_DOCTEST
          >>> from utool.util_dict import *  # NOQA
          >>> import utool as ut
          >>> dict_ = OrderedDict([(2, 'good',), (1, 'ok',), (0, 'junk',), (None, 'UNKNOWN',)])
          >>> inverted_dict = invert_dict(dict_)
          >>> result = ut.repr4(inverted_dict, nl=False)
          >>> print(result)
          {'good': 2, 'ok': 1, 'junk': 0, 'UNKNOWN': None}
  
      Example:
          >>> # ENABLE_DOCTEST
          >>> from utool.util_dict import *  # NOQA
          >>> import utool as ut
          >>> dict_ = {'a': 1, 'b': 0, 'c': 0, 'd': 0, 'e': 0, 'f': 2}
          >>> inverted_dict = invert_dict(dict_, unique_vals=False)
          >>> inverted_dict = ut.map_dict_vals(sorted, inverted_dict)
          >>> result = ut.repr4(inverted_dict, nl=False)
          >>> print(result)
          {0: ['b', 'c', 'd', 'e'], 1: ['a'], 2: ['f']}
      """
      if unique_vals:
          inverted_items = [(val, key) for key, val in six.iteritems(dict_)]
          inverted_dict = type(dict_)(inverted_items)
      else:
          inverted_dict = group_items(dict_.keys(), dict_.values())
      return inverted_dict