def ranges(nums):
    """
    Take a list of numbers (sorted or unsorted) and return all contiguous ranges within the list

    Ranges should be returned as tuples, where the first value is the start of the range and
    the last value is the end (inclusive). Single numbers are returned as tuples where both
    values equal the number. e.g. [0, 2, 3, 4, 6] -> [(0,0), (2,4), (6,6)]

    Parameters
    ----------
    nums : ndarray
        A ndarray containing a list of numbers

    Returns
    -------
    List
        A list containing tuples, where each tuple represents a contiguous range from the
        input ndarray
    """
    nums = sorted(set(nums))
    gaps = [[s, e] for s, e in zip(nums, nums[1:]) if s + 1 < e]
    edges = iter(nums[:1] + sum(gaps, []) + nums[-1:])
    return list(zip(edges, edges))