def example(format_str, year, value):
    format_to_year_to_value_dict = {}
format_to_year_to_value_dict.setdefault(format_str, {}).setdefault(year, []
    ).append(value)
How to initialize nested dictionaries in Python