def recursive_dict_of_lists(d, helper=None, prev_key=None):
    """
    Builds dictionary of lists by recursively traversing a JSON-like
    structure.

    Arguments:
        d (dict): JSON-like dictionary.
        prev_key (str): Prefix used to create dictionary keys like: prefix_key.
            Passed by recursive step, not intended to be used.
        helper (dict): In case d contains nested dictionaries, you can specify
            a helper dictionary with 'key' and 'value' keys to specify where to
            look for keys and values instead of recursive step. It helps with
            cases like: {'action': {'type': 'step', 'amount': 1}}, by passing
            {'key': 'type', 'value': 'amount'} as a helper you'd get
            {'action_step': [1]} as a result.
    """
    d_o_l = {}

    if helper is not None and helper['key'] in d.keys() and helper['value'] in d.keys():
        if prev_key is not None:
            key = f"{prev_key}_{helper['key']}"
        else:
            key = helper['key']

        if key not in d_o_l.keys():
            d_o_l[key] = []
        d_o_l[key].append(d[helper['value']])

        return d_o_l

    for k, v in d.items():
        if isinstance(v, dict):
            d_o_l.update(recursive_dict_of_lists(v, helper=helper, prev_key=k))
        else:
            if prev_key is not None:
                key = f'{prev_key}_{k}'
            else:
                key = k

            if key not in d_o_l.keys():
                d_o_l[key] = []

            if isinstance(v, list):
                d_o_l[key].extend(v)
            else:
                d_o_l[key].append(v)

    return d_o_l