docs: def group_pairs(pair_list):
      """
      Groups a list of items using the first element in each pair as the item and
      the second element as the groupid.
  
      Args:
          pair_list (list): list of 2-tuples (item, groupid)
  
      Returns:
          dict: groupid_to_items: maps a groupid to a list of items
  
      SeeAlso:
          group_items
      """
      # Initialize dict of lists
      groupid_to_items = defaultdict(list)
      # Insert each item into the correct group
      for item, groupid in pair_list:
          groupid_to_items[groupid].append(item)
      return groupid_to_items