code: def merge_self_ranges(src_ranges, is_sorted=False):
      merged_ranges = []
      if len(src_ranges) > 0:
          if not is_sorted:
              src_ranges.sort(key=lambda x: x[0])
          cur_indx = 0
          merged_ranges.append(
              (src_ranges[cur_indx][0], src_ranges[cur_indx][1])
          )
          for cur_indx in range(1, len(src_ranges)):
              if src_ranges[cur_indx][1] > merged_ranges[-1][1]:
                  if src_ranges[cur_indx][0] <= merged_ranges[-1][1]:
                      merged_ranges[-1] = (
                          merged_ranges[-1][0],
                          src_ranges[cur_indx][1],
                      )
                  else:
                      merged_ranges.append(
                          (
                              src_ranges[cur_indx][0],
                              src_ranges[cur_indx][1],
                          )
                      )
      return merged_ranges
  
imports: import collections
  import os
  import sys
label_desc: Use image node_id 2 for calling a global function with example usage: merge_self_ranges(src_ranges, is_sorted) and returns: merged_ranges