I'm trying to create something to prove the concept that moving through a maze with your left hand on the wall works, so I've made a python 3.6 turtle program to do it. It's extremely inefficient, I know, I'm a beginner, but my question is; How would one find the name of a dictionary from it's contents.
Here's an example:
place1 = {"coordinates" : (150, 150), "filled_in": False}
place2 = {"coordinates" : (100, 100), "filled_in": True}
place3 = {"coordinates" : (50, 50), "filled_in": True}
turtle position = 50, 50
Essentially, something like this
?["coordinates" : (50, 50), "filled_in" = True
I want to be able to find the dictionary from the value within it, so I can check if it's filled in.
if (dictionary containing value of "coordinates" : (50, 50))["filled_in"] = False:
do whatever
I understand I've probably formatted everything wrong, but thanks for the help in advance.
You could put them all in one dictionary that can be indexed by the coordinate:
place1 = {"coordinates" : (150, 150), "filled_in": False}
place2 = {"coordinates" : (100, 100), "filled_in": True}
place3 = {"coordinates" : (50, 50), "filled_in": True}
places = {p["coordinates"]: p for p in [place1, place2, place3]}
And then just index it:
>>> places[(50, 50)]['filled_in']
True
>>> places[(150, 150)]['filled_in']
False