def group_dicom_files(dicom_file_paths, header_fields):
dist = SimpleDicomFileDistance(field_weights=header_fields)<EOL>path_list = dicom_file_paths.copy()<EOL>path_groups = DefaultOrderedDict(DicomFileSet)<EOL>while len(path_list) > <NUM_LIT:0>:<EOL><INDENT>file_path1 = path_list.pop()<EOL>file_subgroup = [file_path1]<EOL>dist.set_dicom_file1(file_path1)<EOL>j = len(path_list)-<NUM_LIT:1><EOL>while j >= <NUM_LIT:0>:<EOL><INDENT>file_path2 = path_list[j]<EOL>dist.set_dicom_file2(file_path2)<EOL>if dist.transform():<EOL><INDENT>file_subgroup.append(file_path2)<EOL>path_list.pop(j)<EOL><DEDENT>j -= <NUM_LIT:1><EOL><DEDENT>path_groups[file_path1].from_set(file_subgroup, check_if_dicoms=False)<EOL><DEDENT>return path_groups<EOL>
Gets a list of DICOM file absolute paths and returns a list of lists of
DICOM file paths. Each group contains a set of DICOM files that have
exactly the same headers.

Parameters
----------
dicom_file_paths: list of str
    List or set of DICOM file paths

header_fields: list of str
    List of header field names to check on the comparisons of the DICOM files.

Returns
-------
dict of DicomFileSets
    The key is one filepath representing the group (the first found).