from typing import OrderedDict


def spec_index(spec=None):
    """
    Return the matrix indices of the given spectrum within a 3x3 matrix.  If
    ``spec`` is None, return a dictionary of such indices keyed by spectrum.

    Arguments
    ---------
    spec : str
        Which spectrum to return index for. If None, return dict of all.

    Returns
    -------
    index : dict or list
        Dictionary of indices if spec in None, or list of indices if spec is
        provided.
    """
    inds = OrderedDict(
        [
            ("tt", [0, 0]),
            ("ee", [1, 1]),
            ("bb", [2, 2]),
            ("te", [0, 1]),
            ("eb", [1, 2]),
            ("tb", [0, 2]),
        ]
    )
    if spec is None:
        return inds
    return inds[spec]