by earthboundkid · 5y ago · 0 comments
>>> state2name2visited = {}
>>> state2name2visited.setdefault("PA", {}).setdefault("Joe", []).append("Pittsburgh")
>>> state2name2visited
{'PA': {'Joe': ['Pittsburgh']}}Also setdefault causes confusion for less experienced users in a way that the defaultdict format does not.