from typing import OrderedDict


def get_mpl_linestyles(inverse=None, include_none=True):
    """ Obtain MPL's line styles.

    Parameters
    ----------
    inverse : str, unicode or None, optional
        If given, searches for an MPL line style based on its description. A string containing
        the found MPL line style instead of a dictionary is returned, KeyError raised if no match found.
    include_none : bool, optional
        If True, then the returned dictionary will also contain acceptable variations of none (no line).
        Defaults to True.

    Returns
    -------
    OrderedDict, str or unicode
        A dictionary containing MPL marker line as keys, and line descriptions as values. If the
        inverse parameter is used, a string containing the found MPL line style will be returned.

    Raises
    ------
    KeyError
        If the inverse parameter is used, but a line style corresponding to the passed in description
        does not exist.
    """

    # Create a dict containing MPL linestyles and their descriptions
    _mpl_linestyles = [('-', 'solid'),
                       ('--', 'dashed'),
                       (':',  'dotted'),
                       ('-.', 'dashdot')]

    if include_none:

        _mpl_linestyles += [('none', 'nothing'),
                            ('None', 'nothing'),
                            (None, 'nothing'),
                            (' ',  'nothing'),
                            ('',   'nothing')]

    mpl_linestyles = OrderedDict(_mpl_linestyles)

    # If inverse parameter is specified, find and return an MPL linestyle from its description
    if inverse is not None:

        style_idx = list(mpl_linestyles.values()).index(inverse)
        mpl_linestyle = list(mpl_linestyles.keys())[style_idx]

        return mpl_linestyle

    return mpl_linestyles