import re


def subs_id_by_value(rate_eq, trans_dict):
    """
    Takes a rate equation (rate_eq), which is a string, and substitutes the
    keys in trans_dict for their values.
    ACCEPTS
    rate_eq [str] rate equation
    trans_dict [dict] {key : value}
    RETURNS
    s [str] rate_eq with keys substituted by values
    """
    s = rate_eq[:]
    for key in trans_dict:
        if type(trans_dict[key]) != str:
            s = re.sub(r'\b%s\b' %  key, str(trans_dict[key]), s)
        else:
            s = re.sub(r'\b%s\b' %  key, trans_dict[key], s)
    return s