本文整理汇总了Python中trie.Trie.populate_trie方法的典型用法代码示例。如果您正苦于以下问题:Python Trie.populate_trie方法的具体用法?Python Trie.populate_trie怎么用?Python Trie.populate_trie使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trie.Trie
的用法示例。
在下文中一共展示了Trie.populate_trie方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Trie
# 需要导入模块: from trie import Trie [as 别名]
# 或者: from trie.Trie import populate_trie [as 别名]
from graph import Graph
from trie import Trie
from copy import deepcopy
trie = Trie()
trie.populate_trie('wordlist.txt')
def generate_board(file_name):
with open(file_name) as board_string:
board_string = board_string.read().lower()
board = []
for i in range(0, len(board_string), 10):
board.append(board_string[i:i+10])
return board
def look_for_words(trie, board, depth=8):
return [[words_at_coordinate(trie, board, (x,y), depth) for y in range(0,13)] for x in range(0,10)]
def words_at_coordinate(trie, board, coordinate, depth, base_string=""):
words = []
root = board.graph[coordinate]
if root is None:
return words
board.graph[root.name] = None
base_string += root.name