Finished creating the dictionary of dictionaries to have all paths with their child nodes.

This commit is contained in:
Charles Descamps 2025-02-15 00:57:04 -07:00
parent 39253dfe5e
commit 87a385d98c

View file

@ -33,8 +33,28 @@ class Searcher:
nodeLoc[mapContents[nodeIter][1]] = tuple((mapContents[nodeIter][5], mapContents[nodeIter][6])) nodeLoc[mapContents[nodeIter][1]] = tuple((mapContents[nodeIter][5], mapContents[nodeIter][6]))
# however, this is only taking the first node path it gets to... # however, this is only taking the first node path it gets to...
# I probably need a list instead, that gets updated if the node is not in the node's child list. # I probably need a list instead, that gets updated if the node is not in the node's child list.
nodePaths[mapContents[nodeIter][0]] = tuple((mapContents[nodeIter][1], mapContents[nodeIter][2])) # check if the key exists, if it does, then add the value to the internal dictionary,
print(nodeLoc) # if the internal dictionary doesn't exist, then create it and add the node.
if mapContents[nodeIter][0] not in nodePaths.keys():
nodePaths[mapContents[nodeIter][0]] = dict()
nodePaths[mapContents[nodeIter][0]][mapContents[nodeIter][1]] = mapContents[nodeIter][2]
else:
if nodePaths[mapContents[nodeIter][0]].values() not in nodePaths[mapContents[nodeIter][0]].keys():
nodePaths[mapContents[nodeIter][0]][mapContents[nodeIter][1]] = dict()
nodePaths[mapContents[nodeIter][0]][mapContents[nodeIter][1]] = mapContents[nodeIter][2]
else:
nodePaths[mapContents[nodeIter][0]][mapContents[nodeIter][1]] = mapContents[nodeIter][2]
if mapContents[nodeIter][1] not in nodePaths.keys():
nodePaths[mapContents[nodeIter][1]] = dict()
nodePaths[mapContents[nodeIter][1]][mapContents[nodeIter][0]] = mapContents[nodeIter][2]
else:
if nodePaths[mapContents[nodeIter][1]].values() not in nodePaths[mapContents[nodeIter][1]].keys():
nodePaths[mapContents[nodeIter][1]][mapContents[nodeIter][0]] = dict()
nodePaths[mapContents[nodeIter][1]][mapContents[nodeIter][0]] = mapContents[nodeIter][2]
else:
nodePaths[mapContents[nodeIter][1]][mapContents[nodeIter][0]] = mapContents[nodeIter][2]
# print(nodeLoc)
print(nodePaths) print(nodePaths)
# (b) Show your program loading in the 30-node sample file. # (b) Show your program loading in the 30-node sample file.