def merge_intervals(data):
    """
    data = [(10,20), (15,30), (100, 200)]
    out = [(10,30), (100,200)]
    """
    if len(data)==0:
        return data
    result = []
    saved = list(data[0])
    for st, en in sorted([sorted(t) for t in data]):
        if st <= saved[1]:
            saved[1] = max(saved[1], en)
        else:
            result.append((saved[0], saved[1]))
            saved[0] = st
            saved[1] = en
    result.append(saved)
    return result