<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def range_merge(ranges, dist=0):
 """ Returns merged range. Similar to range_union, except this returns new ranges. [('1', 10, 50)] [('1', 30, 40), ('1', 45, 50)] [('1', 30, 50)] """

    if not ranges:
        return []

    ranges.sort()

    cur_range = list(ranges[0])
    merged_ranges = []
    for r in ranges[1:]:
        # open new range if start > cur_end or seqid != cur_seqid
        if r[1] - cur_range[2] > dist or r[0] != cur_range[0]:
            merged_ranges.append(tuple(cur_range))
            cur_range = list(r)
        else:
            cur_range[2] = max(cur_range[2], r[2])
    merged_ranges.append(tuple(cur_range))

    return merged_ranges