本文整理汇总了Python中trie.Trie.put方法的典型用法代码示例。如果您正苦于以下问题:Python Trie.put方法的具体用法?Python Trie.put怎么用?Python Trie.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trie.Trie
的用法示例。
在下文中一共展示了Trie.put方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_autocomplete
# 需要导入模块: from trie import Trie [as 别名]
# 或者: from trie.Trie import put [as 别名]
def test_autocomplete():
t = Trie()
t.put("rome", 1)
t.put("romulus", 2)
t.put("romani", 3)
t.put("romantic", 4)
assert t.matches("rome") == ["rome"]
assert t.matches("roman") == ["romani", "romantic"]
assert t.matches("rom") == ["rome", "romani", "romulus", "romantic"]
示例2: test_put
# 需要导入模块: from trie import Trie [as 别名]
# 或者: from trie.Trie import put [as 别名]
def test_put():
t = Trie()
t.put("rome", 1)
t.put("romulus", 2)
t.put("romanus", 3)
t.put("romantic", 4)
assert t.get("rome") == 1
assert t.get("romulus") == 2
assert t.get("romanus") == 3
assert t.get("romantic") == 4
t.put("romanus", 23)
assert t.get("romanus") == 23
示例3: Trie
# 需要导入模块: from trie import Trie [as 别名]
# 或者: from trie.Trie import put [as 别名]
"""
read output of Trie inp generator as input.
Create a trie
"""
from trie import Trie
T = Trie()
N = int(raw_input())
#print N
for _ in xrange(N) :
S = str(raw_input())
#print S
T.put(S)
print T
示例4: Trie
# 需要导入模块: from trie import Trie [as 别名]
# 或者: from trie.Trie import put [as 别名]
import sys
from trie import Trie
from bloom_filter import BloomFilter
from tools import get_size
if __name__ == '__main__':
bf_dups = 0
tr = Trie()
bf = BloomFilter(capacity=700000, error_rate=0.001)
with open("words.txt") as file:
for line in file:
tr.put(line.strip())
if bf.put(line.strip()):
print("Duplicate in bloom filter: {0}".format(line.strip()))
bf_dups += 1
print("Trie. number of objects put: {0}".format(len(tr)))
print("Bloom filter. number of objects put: {0}".format(len(bf)))
print()
print("Trie. Size of the object: {0}".format(sys.getsizeof(tr)))
print("Bloom filter. Size of the object: {0}".format(sys.getsizeof(bf)))
print()
print("Trie. Size of the object(full): {0}".format(get_size(tr)))
print("Bloom filter. Size of the object(full): {0}".format(get_size(bf)))
print()
print("Bloom filter errors: {0}".format(bf_dups))
print("----------------------------------------------------------")