Answers for "python dictonary of dictonary"

1

python dictonary of dictonary

from collections import defaultdict
d = defaultdict(dict)
d['dict1']['innerkey'] = 'value'

>>> d  # currently a defaultdict type
defaultdict(<type 'dict'>, {'dict1': {'innerkey': 'value'}})
>>> dict(d)  # but is exactly like a normal dictionary.
{'dict1': {'innerkey': 'value'}}
Posted by: Guest on August-22-2021

Python Answers by Framework

Browse Popular Code Answers by Language