I find myself repeating this pattern when I am fetching from multiple database tables:
records = {'p_key': { "record": r, "A": list(), "B": list(), "C" : list() } for r in db_records}
I often have to group data this way because I cannot do joins across databases or there might be a situation where multiple queries is faster than multiple joins.
But performance-wise I am not sure if there is a lot of overhead to nesting dictionaries like this, and if I would be better served by creating an object with these attributes that becomes the value in the records dictionary. By performance I mean the overall cost in space and time when using a large set of nested dictionaries vs a dictionary of objects.