You will all conform

Programming for the Puzzled

You will all conform

Solution

""" solution.py """

# You will all conform

caps = ['F', 'F', 'B', 'H', 'B', 'F', 'B', 'B', 'B', 'F', 'H', 'F', 'F']

intervals = {}

for i, state in enumerate(caps):

    values = intervals.get(state, [])

    if values:
        (x1, x2) = values[-1]
        if x2 == i - 1:
            x2 = i
            values.pop()
        else:
            x1, x2 = i, i
    else:
        x1, x2 = i, i

    values.append((x1, x2))

    intervals[state] = values

print(intervals)

Output

{'F': [(0, 1), (5, 5), (9, 9), (11, 12)], 'B': [(2, 2), (4, 4), (6, 8)], 'H': [(3, 3), (10, 10)]}