from typing import Dict


def get_names(market, name_attr='name', name_key=False) -> Dict[int, str]:
    """
    Get dictionary of {runner ID: runner name} from a market definition
    - name_attr: optional attribute name to retrieve runner name
    - name_key: optional flag to return {runner name: runner ID} with name as key instead
    """
    if not name_key:
        return {
            runner.selection_id: getattr(runner, name_attr)
            for runner in market.runners
        }
    else:
        return {
            getattr(runner, name_attr): runner.selection_id
            for runner in market.runners
        }