What's the best way to initialize a dict of dicts in Python?
What's the best way to initialize a dict of dicts in Python? Question: A lot of times in Perl, I’ll do something like this: $myhash{foo}{bar}{baz} = 1 How would I translate this to Python? So far I have: if not ‘foo’ in myhash: myhash[‘foo’] = {} if not ‘bar’ in myhash[‘foo’]: myhash[‘foo’][‘bar’] = {} myhash[‘foo’][‘bar’][‘baz’] …
Total answers: 4