nodes: 0, module; 1, function_definition; 2, function_name:groupby_tags; 3, parameters; 4, block; 5, identifier:item_list; 6, identifier:tags_list; 7, expression_statement; 8, expression_statement; 9, for_statement; 10, return_statement; 11, comment:r"""
      case where an item can belong to multiple groups
  
      Args:
          item_list (list):
          tags_list (list):
  
      Returns:
          dict: groupid_to_items
  
      CommandLine:
          python -m utool.util_dict --test-groupby_tags
  
      Example:
          >>> # ENABLE_DOCTEST
          >>> from utool.util_dict import *  # NOQA
          >>> import utool as ut
          >>> tagged_item_list = {
          >>>     'spam': ['meat', 'protein', 'food'],
          >>>     'eggs': ['protein', 'food'],
          >>>     'cheese': ['dairy', 'protein', 'food'],
          >>>     'jam':  ['fruit', 'food'],
          >>>     'banana': ['weapon', 'fruit', 'food'],
          >>> }
          >>> item_list = list(tagged_item_list.keys())
          >>> tags_list = list(tagged_item_list.values())
          >>> groupid_to_items = groupby_tags(item_list, tags_list)
          >>> groupid_to_items = ut.map_vals(sorted, groupid_to_items)
          >>> result = ('groupid_to_items = %s' % (ut.repr4(groupid_to_items),))
          >>> print(result)
          groupid_to_items = {
              'dairy': ['cheese'],
              'food': ['banana', 'cheese', 'eggs', 'jam', 'spam'],
              'fruit': ['banana', 'jam'],
              'meat': ['spam'],
              'protein': ['cheese', 'eggs', 'spam'],
              'weapon': ['banana'],
          }
  
      """; 12, assignment; 13, pattern_list; 14, call; 15, block; 16, identifier:groupid_to_items; 17, identifier:groupid_to_items; 18, call; 19, identifier:tags; 20, identifier:item; 21, identifier:zip; 22, argument_list; 23, for_statement; 24, identifier:defaultdict; 25, argument_list; 26, identifier:tags_list; 27, identifier:item_list; 28, identifier:tag; 29, identifier:tags; 30, block; 31, identifier:list; 32, expression_statement; 33, call; 34, attribute; 35, argument_list; 36, subscript; 37, identifier:append; 38, identifier:item; 39, identifier:groupid_to_items; 40, identifier:tag
code: def groupby_tags(item_list, tags_list):
      r"""
      case where an item can belong to multiple groups
  
      Args:
          item_list (list):
          tags_list (list):
  
      Returns:
          dict: groupid_to_items
  
      CommandLine:
          python -m utool.util_dict --test-groupby_tags
  
      Example:
          >>> # ENABLE_DOCTEST
          >>> from utool.util_dict import *  # NOQA
          >>> import utool as ut
          >>> tagged_item_list = {
          >>>     'spam': ['meat', 'protein', 'food'],
          >>>     'eggs': ['protein', 'food'],
          >>>     'cheese': ['dairy', 'protein', 'food'],
          >>>     'jam':  ['fruit', 'food'],
          >>>     'banana': ['weapon', 'fruit', 'food'],
          >>> }
          >>> item_list = list(tagged_item_list.keys())
          >>> tags_list = list(tagged_item_list.values())
          >>> groupid_to_items = groupby_tags(item_list, tags_list)
          >>> groupid_to_items = ut.map_vals(sorted, groupid_to_items)
          >>> result = ('groupid_to_items = %s' % (ut.repr4(groupid_to_items),))
          >>> print(result)
          groupid_to_items = {
              'dairy': ['cheese'],
              'food': ['banana', 'cheese', 'eggs', 'jam', 'spam'],
              'fruit': ['banana', 'jam'],
              'meat': ['spam'],
              'protein': ['cheese', 'eggs', 'spam'],
              'weapon': ['banana'],
          }
  
      """
      groupid_to_items = defaultdict(list)
      for tags, item in zip(tags_list, item_list):
          for tag in tags:
              groupid_to_items[tag].append(item)
      return groupid_to_items