+ 1
What is "Nested Dictionary"?
I recently read sth about nested dictionary but it seems more confusing than being useful. The question is where nested distionary is useful and how it is used?
1 Resposta
+ 3
It shouldn't be much harder to use than nested lists.
d = {
"123": {"1": 48, "2": 49, "3": 50},
"ABC": {"A": 65, "B": 66, "C": 67},
"abc": {"a": 97, "b": 98, "c": 99},
}
print(d["ABC"]["A"]) #65
print(d["123"]["2"]) #49
print(d["abc"]["c"]) #99
But where it could be used, while using Pygame I've experienced using this kind of dictionary structure useful when working with controls, that change over time:
{"mouse": {"pressed": (0, 0, 0),
"position": (None, None)},
"keyboard": {"pressed": {97: False,
100: False,
115: False,
119: False}},
"events": ()}
But I've lately had some problems with that, and I decided to use OOP instead.