本文整理汇总了Python中trie.Trie.create_avl_tree方法的典型用法代码示例。如果您正苦于以下问题:Python Trie.create_avl_tree方法的具体用法?Python Trie.create_avl_tree怎么用?Python Trie.create_avl_tree使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trie.Trie
的用法示例。
在下文中一共展示了Trie.create_avl_tree方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from trie import Trie [as 别名]
# 或者: from trie.Trie import create_avl_tree [as 别名]
class ControlIt:
def __init__(self):
self.the_trie = Trie()
def file_grab(self):
log = open("content/words1.txt", 'r')
loglist = log.readlines()
log.close()
cl = []
sendc = []
pattern = '^\w+-\s'
for index, line in enumerate(loglist, 0):
if re.search(pattern, line) is not None:
test = re.search(pattern, line)
firstFound = test.string.split(' ', 1)[0]
secondFound = loglist[index + 1]
if not secondFound.split(' ', 1)[0] == "ship":
sendc.append(secondFound.split(' ', 1)[0].lower())
cl.append(firstFound.__add__(secondFound.split(' ', 1)[0]).lower())
try:
with open("content/words1.txt", encoding='UTF-8') as f:
lines = f.read().translate({ord(i): None for i in ';:*.,[]|"�<>()!°&¶/'}).lower().split()
f.close()
except:
with open("content/words1.txt", encoding='latin_1') as f:
lines = f.read().translate({ord(i): None for i in ';:*.,[]|"�<>()!°&¶/'}).lower().split()
f.close()
for index, i in enumerate(lines):
if i.count('-') >= 3 or i == re.search('\w+-\n', i):
lines[index] = None
[lines.append(i) for i in cl]
for i in sendc:
lines = list((x for x in lines if re.sub(i, "", str(x))))
return lines
def grab_file(self):
start_list = self.file_grab()
for i in start_list:
self.the_trie.add(self.the_trie.trie, str(i))
mytrie = self.the_trie.get_trie()
self.the_trie.trie_pickle(mytrie)
# self.ct = self.the_trie
print(mytrie)
def main(self):
self.grab_file()
self.the_trie.create_binary_tree()
self.the_trie.create_avl_tree()