def _format_ranges(ranges):
    """ Create a list of ranges. Range: [h1, s1, v1] to [h2, s2, v2]

    Examples
    --------
    input: [
            [[0, 5], [175, 180]],   # hue, two ranges
            [100, 200],             # saturation, only one range
            [50, 75]                # value, only one range
            ]

    Because Hue has two ranges then the result has two ranges.
    Satur. and val. have only one range and so their first (and now only one) is
    duplicated to each result range.

    result: [
        [[0, 100, 50], [5, 200, 75]],     # first range
        [[175, 100, 50], [180, 200, 75]]  # second
    ]

    """

    # Make all len 2 if any one is len 2
    if max([len(x) for x in ranges]) == 2:
        hues = ranges[0]
        if len(hues) == 1:
            hues *= 2

        saturs = ranges[1]
        if len(saturs) == 1:
            saturs *= 2

        vals = ranges[2]
        if len(vals) == 1:
            vals *= 2
    else:
        hues, saturs, vals = ranges[0], ranges[1], ranges[2]

    new_ranges = []
    for i in range(len(hues)):
        start = [hues[i][0], saturs[i][0], vals[i][0]]
        end = [hues[i][1], saturs[i][1], vals[i][1]]
        new_ranges.append([start, end])

    return new_ranges