from typing import Union


def key(key_name: Union[str, int]) -> Union[str, None]:
    """
    Return the key code of a given command (e.g. from remote control). See "key names".

    Parameters
    ----------
    key_name : str | int
        The code name from "keys list" list
        or the correspondent index

    Returns
    -------
    code : str
        The code of keys list

    Raises
    ------
    TypeError
        If `key_name` type isn't str or int
    
    Examples
    --------
    >>> key('ENTER')
    66
    >>> key(9)
    66
    """
    key_list = [
        ['BACK', 4],
        ['BLUE', 186],
        ['CENTER', 23],
        ['COMPONENT1', 249],
        ['COMPONENT2', 250],
        ['COMPOSITE1', 247],
        ['COMPOSITE2', 248],
        ['DOWN', 20],
        ['END', 123],
        ['ENTER', 66],
        ['ESCAPE', 111],
        ['FAST_FORWARD', 90],
        ['GREEN', 184],
        ['HDMI1', 243],
        ['HDMI2', 244],
        ['HDMI3', 245],
        ['HDMI4', 246],
        ['HOME', 3],
        ['INPUT', 178],
        ['LEFT', 21],
        ['MENU', 82],
        ['MOVE_HOME', 122],
        ['MUTE', 164],
        ['NEXT', 87],
        ['PAIRING', 225],
        ['PAUSE', 127],
        ['PLAY', 126],
        ['PLAY_PAUSE', 85],
        ['POWER', 26],
        ['PREVIOUS', 88],
        ['RED', 183],
        ['RESUME', 224],
        ['REWIND', 89],
        ['RIGHT', 22],
        ['SAT', 237],
        ['SEARCH', 84],
        ['SETTINGS', 176],
        ['SLEEP', 223],
        ['SPACE', 62],
        ['STOP', 86],
        ['SUSPEND', 276],
        ['SYSDOWN', 281],
        ['SYSLEFT', 282],
        ['SYSRIGHT', 283],
        ['SYSUP', 280],
        ['TEXT', 233],
        ['TOP', 122],
        ['UP', 19],
        ['VGA', 251],
        ['VOLUME_DOWN', 25],
        ['VOLUME_UP', 24],
        ['WAKEUP', 224],
        ['YELLOW', 185]]
    if type(key_name) == int:
        return(key_list[int(key_name)][1])
    elif type(key_name) == str:
        for index in range(len(key_list)):
            if str(key_list[index][0]) == key_name:
                code = key_list[index][1]
                return(code)
    else:
        raise TypeError()