本文整理汇总了Python中trie.Trie.startswith方法的典型用法代码示例。如果您正苦于以下问题:Python Trie.startswith方法的具体用法?Python Trie.startswith怎么用?Python Trie.startswith使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trie.Trie
的用法示例。
在下文中一共展示了Trie.startswith方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestTrie
# 需要导入模块: from trie import Trie [as 别名]
# 或者: from trie.Trie import startswith [as 别名]
#.........这里部分代码省略.........
self.assertTrue("Bar" in self.trie)
def test_basicRemoval(self):
self.trie["Foo"] = True
self.assertTrue(self.trie["Foo"])
del self.trie["Foo"]
self.assertRaises(KeyError, self._square_brackets, "Foo")
self.assertEquals(0, len(self.trie))
self.assertEquals(0, self.trie.nodeCount())
self.assertFalse("Foo" in self.trie)
def test_MixedTypes(self):
self.trie["Foo"] = True
self.trie[[1, 2, 3]] = True
self.assertTrue(self.trie["Foo"])
self.assertTrue(self.trie[[1, 2, 3]])
self.assertTrue([1, 2, 3] in self.trie)
self.assertTrue("Foo" in self.trie)
del self.trie[[1, 2, 3]]
self.assertFalse([1, 2, 3] in self.trie)
def test_Iteration(self):
self.trie["Foo"] = True
self.trie["Bar"] = True
self.trie["Grok"] = True
for k in self.trie:
self.assertTrue(k in self.trie)
self.assertTrue(self.trie[k])
def test_Addition(self):
self.trie["Foo"] = True
t2 = Trie()
t2["Food"] = True
t3 = t2 + self.trie
self.assertTrue("Foo" in self.trie)
self.assertFalse("Food" in self.trie)
self.assertTrue("Food" in t2)
self.assertFalse("Foo" in t2)
self.assertTrue("Foo" in t3)
self.assertTrue("Food" in t3)
def test_Subtraction(self):
self.trie["Food"] = True
self.trie["Foo"] = True
t2 = Trie()
t2["Food"] = True
t3 = self.trie - t2
t4 = t2 - self.trie
self.assertTrue("Food" in self.trie)
self.assertTrue("Foo" in self.trie)
self.assertTrue("Food" in t2)
self.assertTrue("Foo" in t3)
self.assertFalse("Food" in t3)
self.assertFalse("Foo" in t4)
self.assertFalse("Food" in t4)
def test_SelfAdd(self):
self.trie["Foo"] = True
t2 = Trie()
t2["Food"] = True
self.assertTrue("Foo" in self.trie)
self.assertFalse("Food" in self.trie)
self.assertTrue("Food" in t2)
self.assertFalse("Foo" in t2)
self.trie += t2
self.assertTrue("Foo" in self.trie)
self.assertTrue("Food" in self.trie)
def test_SelfSub(self):
self.trie["Foo"] = True
self.trie["Food"] = True
t2 = Trie()
t2["Food"] = True
self.assertTrue("Food" in self.trie)
self.assertTrue("Foo" in self.trie)
self.assertTrue("Food" in t2)
self.trie -= t2
self.assertFalse("Food" in self.trie)
self.assertTrue("Foo" in self.trie)
self.assertTrue("Food" in t2)
def test_SelfGet(self):
self.trie["Foo"] = True
self.assertTrue(self.trie["Foo"])
self.assertRaises(KeyError, self._square_brackets, "Food")
self.assertEquals("Bar", self.trie.get("Food", "Bar"))
self.assertEquals("Bar", self.trie.get("Food", default="Bar"))
self.assertTrue(self.trie.get("Foo"))
self.assertTrue(self.trie.get("Food") is None)
def test_Startswith(self):
self.trie['lol'] = 1
self.trie['lautre'] = 1
self.trie['laurentz'] = 1
self.trie['foobar'] = 1
self.assertEquals(['laurentz','lautre','lol'], self.trie.startswith('l'))
self.assertEquals(['laurentz','lautre'], self.trie.startswith('la'))
self.assertEquals(['laurentz'], self.trie.startswith('laur'))
self.assertEquals([], self.trie.startswith('bar'))