-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpath.py
More file actions
23 lines (18 loc) · 684 Bytes
/
path.py
File metadata and controls
23 lines (18 loc) · 684 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import collections
class Path(object):
"""Path object represents a single node in a words path
It's used for finding path between two corresponding words.
Technically it is a reversed linked list where each node keeps a value set to a
certain word and a pointer to the previous node.
"""
def __init__(self, word, previous=None):
self.word = word
self.previous = previous
def get_path(self):
"""Generate path starting from this path."""
node = self
result = collections.deque()
while node is not None:
result.appendleft(node.word)
node = node.previous
return list(result)