-2

I have this dictionary in my Python code:

LOCATIONS = {
    1: {
        "Name": "West of house",
        "x": 0, "y": 0, "z": 0,
    },
    2: {
        "Name": "Test Location",
        "x": 0, "y": 0, "z": 0,
    }
}

How can I check the current values of x, y, and z and match them to a location and get its name?

It_is_Chris
  • 13,504
  • 2
  • 23
  • 41

1 Answers1

0

Do you want something like this?:

name = None
for values in LOCATIONS.values():
    if (values["x"], values["y"], values["z"]) == (0, 0, 0):
        name = values["Name"]

Keep in mind that if there are multiple names, that have the same x, y & z then the last one will be the output. If you want all of them then you should store them in a container like a list.

CozyCode
  • 484
  • 4
  • 13