import collections


def map_to_functions(features, functions):
    """
    Create and return a mapping of feature keys to feature functions.

    Each feature's key is a (tbl, typ) pair.  To support applying
    multiple functions to the same data, a key can map to multiple
    feature functions, so the values in the mapping are lists of
    (feature_id, feature_function) pairs.

    features:
        Iterable of feature records.
    functions:
        Corresponding iterable of feature functions.
    """
    feat_key2idsfuncs = collections.defaultdict(list)
    for feat, func in zip(features, functions):
        id, _, tbl, typ, _, _, _, _ = feat
        feat_key2idsfuncs[tbl, typ].append((id, func))
    return feat_key2idsfuncs