for iteration in config: dic[iteration['name']] = defaultdict(lambda: defaultdict(int)) for item in dic[iteration['prior']].items(): key = eval(construct(iteration)) dic[iteration['name']][key]['i'] += item[1]['i'] dic[iteration['name']][key]['s'] += item[1]['s']