def change_waveunit(wave, oldunits, newunits):
    """Return wavelengths converted to new wavelength units.

    Parameters
    ----------
    wave : float or list of floats
        Input wavelength(s) in units specified by `oldunits`.

    oldunits : str
        Input units for `wave`. Allowed values are described in the table
        below. Values are case insensitive.

    newunits : str
        Units for returned wavelength(s). Allowed values are described in
        the table below. Values are case insensitive.

    Returns
    -------
    float or list of floats
        Output wavelength(s) in units specified by `newunits`.

    Raises
    ------
    ValueError
        If either `oldunits` or `newunits` is not a recognized wavelength
        unit, as described in the table below.


    The following table defines allowed values for `newunits` and `oldunits`.

    +-----------------+---------------------+
    | Unit            | Description         |
    +=================+=====================+
    | :kbd:`'A'`      | Angstroms           |
    +-----------------+---------------------+
    | :kbd:`'nm'`     | nanometers          |
    +-----------------+---------------------+
    | :kbd:`'um'`     | micrometers         |
    +-----------------+---------------------+
    | :kbd:`'micron'` | micrometers         |
    +-----------------+---------------------+
    | :kbd:`'cm^-1'`  | inverse centimeters |
    +-----------------+---------------------+
    | :kbd:`'1/cm'`   | inverse centimeters |
    +-----------------+---------------------+

    Examples
    --------
    >>> from sme.util import change_waveunit
    >>> change_waveunit(5000, 'A', 'nm')
    500.0
    >>> change_waveunit([10000, 20000], 'cm^-1', 'a')
    [10000.0, 5000.0]
    """
    oldlow = oldunits.lower()
    newlow = newunits.lower()
    if newlow == oldlow:
        return wave
    factor = {
        'a': 1.0, 'nm': 10.0, 'um': 1e4, 'micron': 1e4,
        'cm^-1': 1e8, '1/cm': 1e8}
    try:
        old_to_A = factor[oldlow]
        A_to_new = factor[newlow]
    except KeyError:
        raise ValueError(
            f"invalid wavelength unit: old='{oldunits}', new='{newunits}'\n"
            f"Valid wavelength units: '" + "', '".join(factor.keys()) + "'")
    old_new = old_to_A / A_to_new
    if oldlow in ['cm^-1', '1/cm']:
        try:
            return [old_new / w for w in wave]
        except TypeError:
            return old_new / wave
    elif newlow in ['cm^-1', '1/cm']:
        try:
            return [1.0 / old_new / w for w in wave]
        except TypeError:
            return 1.0 / old_new / wave
    else:
        try:
            return [old_new * w for w in wave]
        except TypeError:
            return old_new * wave