I have a dictionary where I am constantly doing stuff like this in my code:
special_dict = {}
# ...
if username not in special_dict:
special_dict[username] = {}
for subkey in ["Subkey1", "Subkey2", "Subkey3"]:
special_dict[username][subkey] = [] # or {}, etc, depending on usecase
Basically I want a dictionary where for every username, the value is yet another dictionary of three specific subkeys, and then those values are lists or sets or what have you.
I'm familiar with defaultdict but I am not sure how to make the "value type" here something very specific. Normally I do defaultdict(list)
if I want every value to be a list by default, but is there a way to make the default not a list but in itself a specific type of dictionary?
Ideally, in the end what I want to be able to do is special_dict[username][subkey].append(item)
and not have to worry about whether or not the username exists first, because if it doesn't, it'll become a key and have the three subkeys formed.