              score_total = 0
              for j in range(0, img_list_len):
                  if i == j:
                      continue
                  score_total += cv2.compareHist(img_list[i][1], img_list[j][1], distance)
              img_list[i][2] = score_total
  
          logger.info("Sorting...")
          img_list = sorted(img_list, key=operator.itemgetter(2), reverse=True)
          return img_list
 
</s> remove         for i in tqdm(range(0, img_list_len), desc="Comparing", file=sys.stdout):
 </s> add         for i in tqdm(range(0, img_list_len), desc="Comparing histograms", file=sys.stdout): </s> remove         img_list = sorted(img_list, key=operator.itemgetter(2), reverse=True)
        return img_list
 </s> add         return sorted(img_list, key=lambda x: x[2], reverse=True) </s> remove         logger.info("Comparing histograms...")
 </s> add  </s> remove         for i in tqdm(range(0, img_list_len - 1), desc="Comparing...", file=sys.stdout):
 </s> add         for i in tqdm(range(0, img_list_len - 1), desc="Comparing", file=sys.stdout): </s> remove                 score = cv2.compareHist(img_list[i][1], img_list[j][1], distance)
 </s> add                 score = cv2.compareHist(img_list[i][1], img_list[j][1], cv2.HISTCMP_BHATTACHARYYA)
                score_total += cv2.compareHist(img_list[i][1],
                                               img_list[j][1],
                                               cv2.HISTCMP_BHATTACHARYYA)
              score_total = 0
              for j in range(0, img_list_len):
                  if i == j:
                      continue
                score_total += cv2.compareHist(img_list[i][1],
                                               img_list[j][1],
                                               cv2.HISTCMP_BHATTACHARYYA)
              img_list[i][2] = score_total
  
          logger.info("Sorting...")
          img_list = sorted(img_list, key=operator.itemgetter(2), reverse=True)
          return img_list
keep keep keep keep replace keep keep keep keep keep
 tools.sort
  - Add sort by size
  - Centralize some of the image loading routines 
tools/sort/sort.py