本文整理汇总了Python中trie.Trie.find_all方法的典型用法代码示例。如果您正苦于以下问题:Python Trie.find_all方法的具体用法?Python Trie.find_all怎么用?Python Trie.find_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trie.Trie
的用法示例。
在下文中一共展示了Trie.find_all方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_08_find_all
# 需要导入模块: from trie import Trie [as 别名]
# 或者: from trie.Trie import find_all [as 别名]
def test_08_find_all(self):
t = Trie()
l = ["spam", "spammer", "spamhouse", "spammers", "spams", "bacon"]
for i in l:
t[i] = i
self.assertEqual(t.find_all("bac"), ["bacon"])
self.assertEqual(sorted(t.find_all("spam")), sorted(l[:-1]))
self.assertEqual(sorted(t.find_all("")), sorted(l))
示例2: test_09_delete
# 需要导入模块: from trie import Trie [as 别名]
# 或者: from trie.Trie import find_all [as 别名]
def test_09_delete(self):
t = Trie()
l = ["one", "two", "three", "onesee", "spam", "spammers", "spamhouse", "spams"]
for i in l:
t[i] = i
self.assertEqual(sorted(t.find_all("spam")), sorted(l[-4:]))
self.assertEqual(t.delete("spam"), "spam")
self.assertEqual(sorted(t.find_all("spam")), sorted(l[-3:]))
self.assertRaises(KeyError, t.delete, "four")
self.assertEqual(sorted(t.find_all("spam")), sorted(l[-3:]))
s, n = t.get_node("spam")
self.assertFalse(n.has_value)
示例3: test_10_delete_all
# 需要导入模块: from trie import Trie [as 别名]
# 或者: from trie.Trie import find_all [as 别名]
def test_10_delete_all(self):
t = Trie()
l = ["one", "two", "three", "onesee", "spam", "spammers", "spamhouse", "spams"]
for i in l:
t[i] = i
self.assertEqual(sorted(t.delete_all("spam")), sorted(l[-4:]))
self.assertEqual(t.find_all("spam"), [])
self.assertEqual(len(list(t)), 4)
self.assertEqual(sorted(t.delete_all("o")), sorted(["one", "onesee"]))
self.assertEqual(t.find_all("o"), [])
self.assertEqual(len(list(t)), 2)
self.assertEqual(t.delete_all("four"), [])
self.assertEqual(len(list(t)), 2)
self.assertEqual(sorted(t.delete_all("")), sorted(l[1:3]))
self.assertEqual(list(t), [])