forked from rahul-1996/DeathByVocabulary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1.py
25 lines (22 loc) · 695 Bytes
/
1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import networkx as nx
import collections
def transformWord(graph, start, goal):
paths=collections.deque([ [start] ])
extended=set()
while len(paths)!=0:
currentPath=paths.popleft()
currentWord=currentPath[-1]
if currentWord==goal:
return currentPath
elif currentWord in extended:
continue
extended.add(currentWord)
transforms=graph[currentWord]
for word in transforms:
if word not in currentPath:
#avoid loops
paths.append(currentPath[:]+[word])
#no transformation
return []
G=nx.read_gpickle('test.gpickle')
print(transformWord(G,'time','space'))