本文整理汇总了Python中trie.Trie.from_dat_file方法的典型用法代码示例。如果您正苦于以下问题:Python Trie.from_dat_file方法的具体用法?Python Trie.from_dat_file怎么用?Python Trie.from_dat_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trie.Trie
的用法示例。
在下文中一共展示了Trie.from_dat_file方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from trie import Trie [as 别名]
# 或者: from trie.Trie import from_dat_file [as 别名]
def main():
dim = int(os.environ.get('DIM', '3'))
words_dat_file = os.environ.get('WORDS_DAT', 'words-en.dat')
edges = list(map(lambda s: s.strip(), sys.stdin.read().split()))
edge_map = {}
valid_words = Trie.from_dat_file(words_dat_file)
if len(edges) % dim != 0:
raise ValueError('edges length={!r} not divisible by dim={!r}'.format(
len(edges), dim))
for row in range(0, dim):
for col in range(0, dim):
idx = (row * dim) + col
if idx >= len(edges):
continue
edge_map[(row, col)] = Edge((row, col), edges[idx])
for (row, col), edge in edge_map.items():
for sibling in ((row, col - 1), (row, col + 1), (row - 1, col),
(row + 1, col), (row - 1, col - 1), (row - 1, col + 1),
(row + 1, col + 1), (row + 1, col - 1)):
debug('checking {!r} sibling {!r}'.format((row, col), sibling))
if edge_map.get(sibling) is not None:
edge.siblings.add(edge_map[sibling])
debug(' added sibling {!r} to {!r}'.format(sibling, edge))
for origin in sorted(edge_map.keys()):
for dest in sorted(edge_map.keys()):
if origin == dest:
continue
debug('getting paths from origin={!r} to dest={!r}'.format(
origin, dest))
for path in dfs_paths(edge_map, valid_words, origin, dest):
print(''.join(list(map(lambda e: edge_map[e].value, path))))
return 0