@staticmethod<EOL><INDENT>def _merge_ranges(ranges, max_gap):<DEDENT>
merged_ranges = []<EOL>for range in ranges:<EOL><INDENT>if merged_ranges:<EOL><INDENT>curr_start, curr_end = range<EOL>pre_start, pre_end = merged_ranges[-<NUM_LIT:1>]<EOL>if curr_start - pre_end < max_gap:<EOL><INDENT>merged_ranges[-<NUM_LIT:1>] = (pre_start, max(curr_end, pre_end))<EOL><DEDENT>else:<EOL><INDENT>merged_ranges.append(range)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>merged_ranges.append(range)<EOL><DEDENT><DEDENT>return merged_ranges<EOL>
Merge ranges which are closer than max_gap
:param ranges: assumed to be sorted on start
:param max_gap: allowed gap between ranges
:return: new ranges