import typing
import ast


def getitem(
    entity_name: str, key: typing.Union[ast.Constant, ast.Subscript]
) -> ast.Subscript:
    """Get dictionary item value.
    Generates following code: `entity_name[key]`

    :param entity_name: dictionary variable name
    :param key: dictionary key or list index
    :returns: a subscript expression
    """
    return ast.Subscript(
        value=ast.Name(id=entity_name, ctx=ast.Load()), slice=key, ctx=ast.Load()
    )