code: def sort_dicoms(dicoms):
      dicom_input_sorted_x = sorted(dicoms, key=lambda x: (x.ImagePositionPatient[0]))
      dicom_input_sorted_y = sorted(dicoms, key=lambda x: (x.ImagePositionPatient[1]))
      dicom_input_sorted_z = sorted(dicoms, key=lambda x: (x.ImagePositionPatient[2]))
      diff_x = abs(dicom_input_sorted_x[-1].ImagePositionPatient[0] - dicom_input_sorted_x[0].ImagePositionPatient[0])
      diff_y = abs(dicom_input_sorted_y[-1].ImagePositionPatient[1] - dicom_input_sorted_y[0].ImagePositionPatient[1])
      diff_z = abs(dicom_input_sorted_z[-1].ImagePositionPatient[2] - dicom_input_sorted_z[0].ImagePositionPatient[2])
      if diff_x >= diff_y and diff_x >= diff_z:
          return dicom_input_sorted_x
      if diff_y >= diff_x and diff_y >= diff_z:
          return dicom_input_sorted_y
      if diff_z >= diff_x and diff_z >= diff_y:
          return dicom_input_sorted_z