def maximize_nonoverlapping_count(intervals):
    tree = SortedSet(intervals, key=lambda start_end: (start_end[1], start_end[1] - start_end[0]),
        updator=OverlappingIntervalsUpdator)
result = []
Python: структура данных динамического интервала