I have a nested dict:
KEYS1 = ("A", "B", "C")
KEYS2 = ("X", "Y", "Z")
d = dict.fromkeys(KEYS1, dict.fromkeys(KEYS2, 0))
I'd now like to embed its values in a string using format, something like
print("{A,X:d}".format(**d))
That does not work. Any suggestions on how to do this correctly?
d = dict.fromkeys(KEYS1, dict.fromkeys(KEYS2, 0))- watch out. Every value in the outer dict is the same inner dict, so anything you do tod['A']will be visible throughd['B'].dictwith a genexp in Python <2.7.{key1: dict.fromkeys(KEYS2, 0) for key1 in KEYS1}, ordict((key1, dict.fromkeys(KEYS2, 0)) for key1 in KEYS1). In cases where the inner values also need to be distinct, you can replace the innerfromkeyswith a dict comprehension too.