nodes: 0, module; 1, function_definition; 2, function_name:sort_group; 3, parameters; 4, block; 5, identifier:d; 6, default_parameter; 7, expression_statement; 8, comment:# First, sort the paths in order (this must be a couple: (parent_dir, filename), so that there's no ambiguity because else a file at root will be considered as being after a folder/file since the ordering is done alphabetically without any notion of tree structure).; 9, expression_statement; 10, comment:# Pop the first item in the ordered list; 11, expression_statement; 12, while_statement; 13, comment:# No element, then we just return; 14, if_statement; 15, identifier:return_only_first; 16, False; 17, string; 18, assignment; 19, assignment; 20, parenthesized_expression; 21, block; 22, comparison_operator:base_elt[1] is None; 23, block; 24, comment:# Else, we will now group equivalent files together (remember we are working on multiple directories, so we can have multiple equivalent relative filepaths, but of course the absolute filepaths are different).; 25, else_clause; 26, string_content:Sort a dictionary of relative paths and cluster equal paths together at the same time; 27, identifier:d_sort; 28, call; 29, identifier:base_elt; 30, tuple; 31, boolean_operator; 32, expression_statement; 33, subscript; 34, None; 35, return_statement; 36, comment:# Init by creating the first group and pushing the first ordered filepath into the first group; 37, block; 38, identifier:sort_dict_of_paths; 39, argument_list; 40, unary_operator; 41, None; 42, comparison_operator:base_elt[1] is None; 43, identifier:d_sort; 44, assignment; 45, identifier:base_elt; 46, integer:1; 47, None; 48, expression_statement; 49, expression_statement; 50, if_statement; 51, return_statement; 52, identifier:d; 53, integer:1; 54, subscript; 55, None; 56, identifier:base_elt; 57, call; 58, assignment; 59, call; 60, identifier:d_sort; 61, comment:# For each subsequent filepath; 62, block; 63, identifier:lst; 64, identifier:base_elt; 65, integer:1; 66, attribute; 67, argument_list; 68, identifier:lst; 69, list; 70, attribute; 71, argument_list; 72, for_statement; 73, identifier:d_sort; 74, identifier:pop; 75, integer:0; 76, identifier:lst; 77, identifier:append; 78, list; 79, identifier:elt; 80, identifier:d_sort; 81, comment:# If the filepath is not empty (generator died); 82, block; 83, identifier:base_elt; 84, if_statement; 85, comparison_operator:elt[1] is not None; 86, comment:# If the filepath is the same to the latest grouped filepath, we add it to the same group; 87, block; 88, subscript; 89, None; 90, if_statement; 91, identifier:elt; 92, integer:1; 93, comparison_operator:elt[1] == base_elt[1]; 94, block; 95, comment:# Else the filepath is different: we create a new group, add the filepath to this group, and replace the latest grouped filepath; 96, else_clause; 97, subscript; 98, subscript; 99, expression_statement; 100, block; 101, identifier:elt; 102, integer:1; 103, identifier:base_elt; 104, integer:1; 105, call; 106, if_statement; 107, expression_statement; 108, expression_statement; 109, comment:# replace the latest grouped filepath; 110, attribute; 111, argument_list; 112, identifier:return_only_first; 113, block; 114, call; 115, assignment; 116, subscript; 117, identifier:append; 118, identifier:elt; 119, break_statement; 120, comment:# break here if we only need the first group; 121, attribute; 122, argument_list; 123, identifier:base_elt; 124, identifier:elt; 125, identifier:lst; 126, unary_operator; 127, identifier:lst; 128, identifier:append; 129, list; 130, integer:1; 131, identifier:elt
code: def sort_group(d, return_only_first=False):
      ''' Sort a dictionary of relative paths and cluster equal paths together at the same time '''
      # First, sort the paths in order (this must be a couple: (parent_dir, filename), so that there's no ambiguity because else a file at root will be considered as being after a folder/file since the ordering is done alphabetically without any notion of tree structure).
      d_sort = sort_dict_of_paths(d)
      # Pop the first item in the ordered list
      base_elt = (-1, None)
      while (base_elt[1] is None and d_sort):
          base_elt = d_sort.pop(0)
      # No element, then we just return
      if base_elt[1] is None:
          return None
      # Else, we will now group equivalent files together (remember we are working on multiple directories, so we can have multiple equivalent relative filepaths, but of course the absolute filepaths are different).
      else:
          # Init by creating the first group and pushing the first ordered filepath into the first group
          lst = []
          lst.append([base_elt])
          if d_sort:
              # For each subsequent filepath
              for elt in d_sort:
                  # If the filepath is not empty (generator died)
                  if elt[1] is not None:
                      # If the filepath is the same to the latest grouped filepath, we add it to the same group
                      if elt[1] == base_elt[1]:
                          lst[-1].append(elt)
                      # Else the filepath is different: we create a new group, add the filepath to this group, and replace the latest grouped filepath
                      else:
                          if return_only_first: break  # break here if we only need the first group
                          lst.append([elt])
                          base_elt = elt # replace the latest grouped filepath
          return lst