parameters: (ranges)
return_statement: return combined
docstring: Collapses overlapping ranges together. Input ranges are tuples of (start, end) in the normal
      Python manner where the end isn't included.
docstring_summary: Collapses overlapping ranges together. Input ranges are tuples of (start, end) in the normal
      Python manner where the end isn't included.
docstring_tokens: Collapses overlapping ranges together . Input ranges are tuples of ( start end ) in the normal Python manner where the end isn t included .
function: def simplify_ranges(ranges):
      """
      Collapses overlapping ranges together. Input ranges are tuples of (start, end) in the normal
      Python manner where the end isn't included.
      """
      fixed_ranges = []
      for int_range in ranges:
          if int_range[0] > int_range[1]:
              fixed_ranges.append((int_range[1], int_range[0]))
          elif int_range[0] < int_range[1]:
              fixed_ranges.append(int_range)
      starts_ends = [(x[0], 1) for x in fixed_ranges]
      starts_ends += [(x[1], -1) for x in fixed_ranges]
      starts_ends.sort(key=lambda x: x[0])
      current_sum = 0
      cumulative_sum = []
      for start_end in starts_ends:
          current_sum += start_end[1]
          cumulative_sum.append((start_end[0], current_sum))
      prev_depth = 0
      start = 0
      combined = []
      for pos, depth in cumulative_sum:
          if prev_depth == 0:
              start = pos
          elif depth == 0:
              combined.append((start, pos))
          prev_depth = depth
      return combined
function_tokens: def simplify_ranges ( ranges ) : fixed_ranges = [ ] for int_range in ranges : if int_range [ 0 ] > int_range [ 1 ] : fixed_ranges . append ( ( int_range [ 1 ] , int_range [ 0 ] ) ) elif int_range [ 0 ] < int_range [ 1 ] : fixed_ranges . append ( int_range ) starts_ends = [ ( x [ 0 ] , 1 ) for x in fixed_ranges ] starts_ends += [ ( x [ 1 ] , - 1 ) for x in fixed_ranges ] starts_ends . sort ( key = lambda x : x [ 0 ] ) current_sum = 0 cumulative_sum = [ ] for start_end in starts_ends : current_sum += start_end [ 1 ] cumulative_sum . append ( ( start_end [ 0 ] , current_sum ) ) prev_depth = 0 start = 0 combined = [ ] for pos , depth in cumulative_sum : if prev_depth == 0 : start = pos elif depth == 0 : combined . append ( ( start , pos ) ) prev_depth = depth return combined