<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def color_sequence(palette=None, n_colors=None):
 """ Return a `ListedColormap` object from a named sequence palette. Useful for continuous color scheme values and color maps. Calling this function with ``palette=None`` will return the default color sequence: Color Brewer RdBu. Parameters palette : None or str or sequence Name of a palette or ``None`` to return the default palette. If a sequence the input colors are used to create a ListedColormap. The currently implemented color sequences are from Color Brewer. Available palette names from :py:mod:`yellowbrick.colors.palettes` are: .. hlist:: :columns: 3 * :py:const: Blues * :py:const: BrBG * :py:const: BuGn * :py:const: BuPu * :py:const: GnBu * :py:const: Greens * :py:const: Greys * :py:const: OrRd * :py:const: Oranges * :py:const: PRGn * :py:const: PiYG * :py:const: PuBu * :py:const: PuBuGn * :py:const: PuOr * :py:const: PuRd * :py:const: Purples * :py:const: RdBu * :py:const: RdGy * :py:const: RdPu * :py:const: RdYlBu * :py:const: RdYlGn * :py:const: Reds * :py:const: Spectral * :py:const: YlGn * :py:const: YlGnBu * :py:const: YlOrBr * :py:const: YlOrRd * :py:const: ddl_heat n_colors : None or int Number of colors in the palette. If ``None``, the default will depend on how ``palette`` is specified - selecting the largest sequence for that palette name. Note that sequences have a minimum lenght of 3 - if a number of colors is specified that is not available for the sequence a ``ValueError`` is raised. Returns ------- colormap Returns a ListedColormap object, an artist object from the matplotlib library that can be used wherever a colormap is necessary. """

    # Select the default colormap if None is passed in.
    palette = palette or DEFAULT_SEQUENCE

    # Create a listed color map from the sequence
    if not isinstance(palette, str):
        return mplcol.ListedColormap(palette)

    # Otherwise perform a case-insensitive lookup
    sequences = {key.lower(): key for key in SEQUENCES.keys()}
    if palette.lower() not in sequences:
        raise YellowbrickValueError(
            "'{}' is not a recognized palette!".format(palette)
        )

    # Collect the palette into the dictionary of lists.
    n_palettes = SEQUENCES[sequences[palette.lower()]]

    # If no definitive color is passed in, maximize it.
    if n_colors is None:
        n_colors = max(n_palettes.keys())

    else:
        if n_colors not in n_palettes.keys():
            raise YellowbrickValueError(
                "No {} palette of length {}".format(palette, n_colors)
            )

    # Return the color map from the sequence
    return mplcol.ListedColormap(n_palettes[n_colors], name=palette, N=n_colors)