Python - Determine overlaps of 3 ranges

overlap, python, range

Solution

The overlap goes from the highest start point to the lowest end point:

ranges = [(10,20), (15,25), (18,30)]
starts, ends = zip(*ranges)
result = range(max(starts), min(ends) + 1)

Test:

>>> print(*result)
18 19 20

Problem

I had a question regarding how I should go about determining overlaps of three ranges in Python without using any existing libraries : For instance if I have three ranges as (10,20)(15,25)(18,30), how should I go about finding overlaps between them ? My answer should be (18,19,20) Any help would be much appreciated. Thanks !

Original source

Related problems