def example(format_str, year, value):
    format_to_year_to_value_dict = defaultdict(lambda : defaultdict(list))
format_to_year_to_value_dict[format_str][year].append(value)
How to initialize nested dictionaries in Python