from typing import List
from typing import Dict


def entity_to_feature_row_dict(entities: List, prefix: str = ''):
    """Relates entities to its rumber in the feature matrix.

    Parameters
    ----------
    entities : List[str]
        A list of entities, named arbitrarily. Usually serve as ID to a
        different data structure.
    prefix : str
        Prefix in the dictionary. Helpful if dict is merged with another dict.

    Returns
    -------
    entity_to_feature_row_dict: Dict[str, int]
        Relates a feature row to an identiy
    feature_row_to_entity_dict: Dict[int, str]
        Relates an entity to the corresponding feature.
    i: int
        Total number feature rows.

    """
    entity_to_feature_row_dict = {}
    feature_row_to_entity_dict: Dict = {}
    i = 0
    for entity in entities:
        if prefix == '':
            entity = '{}'.format(entity)
        else:
            entity = '{}_{}'.format(prefix, entity)
        feature_row_to_entity_dict[i] = entity
        entity_to_feature_row_dict[entity] = i
        i = i + 1

    return entity_to_feature_row_dict, feature_row_to_entity_dict, i