I\'m having trouble understanding nested dictionary comprehensions in Python 3. The result I\'m getting from the example below outputs the correct structure without error,
Adding some line-breaks and indentation:
data = {
outer_k: {inner_k: myfunc(inner_v)}
for outer_k, outer_v in outer_dict.items()
for inner_k, inner_v in outer_v.items()
}
... makes it obvious that you actually have a single, "2-dimensional" dict comprehension. What you actually want is probably:
data = {
outer_k: {
inner_k: myfunc(inner_v)
for inner_k, inner_v in outer_v.items()
}
for outer_k, outer_v in outer_dict.items()
}
(which is exactly what Blender suggested in his answer, with added whitespace).