| 10 | |
| 11 | |
| 12 | class Trie: |
| 13 | |
| 14 | def __init__(self, eos): |
| 15 | self.root = TreeNode() |
| 16 | self.eos = eos |
| 17 | |
| 18 | def insert(self, word): |
| 19 | cur = self.root |
| 20 | for c in word: |
| 21 | cur = cur.child[c] |
| 22 | |
| 23 | def get_next_layer(self, word): |
| 24 | cur = self.root |
| 25 | for c in word: |
| 26 | cur = cur.child.get(c) |
| 27 | if cur is None: |
| 28 | return [self.eos] |
| 29 | return list(cur.child.keys()) |