本文整理汇总了Python中trie.Trie.traversal方法的典型用法代码示例。如果您正苦于以下问题:Python Trie.traversal方法的具体用法?Python Trie.traversal怎么用?Python Trie.traversal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trie.Trie
的用法示例。
在下文中一共展示了Trie.traversal方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_small_traversal
# 需要导入模块: from trie import Trie [as 别名]
# 或者: from trie.Trie import traversal [as 别名]
def test_small_traversal():
from trie import Trie
my_trie = Trie()
my_trie.insert('word')
my_trie.insert('worldly')
my_trie.insert('otherword')
assert sorted([x for x in my_trie.traversal()]) == ['otherword', 'word', 'worldly']
示例2: test_traversals_on_empty
# 需要导入模块: from trie import Trie [as 别名]
# 或者: from trie.Trie import traversal [as 别名]
def test_traversals_on_empty():
"""Test traversal for aan empty."""
from trie import Trie
t = Trie()
result = []
for item in t.traversal(t.root):
result.append(item)
assert result == []
示例3: test_traversal_no_words
# 需要导入模块: from trie import Trie [as 别名]
# 或者: from trie.Trie import traversal [as 别名]
def test_traversal_no_words():
"""Test traversal on trie with no words."""
from trie import Trie
word_list = []
trie = Trie()
for word in trie.traversal(start=trie.container):
word_list.append(word)
assert word_list == []
示例4: test_traversal
# 需要导入模块: from trie import Trie [as 别名]
# 或者: from trie.Trie import traversal [as 别名]
def test_traversal():
"""Test traversal works on multiple items."""
from trie import Trie
t = Trie()
t.insert("cat")
t.insert("cats")
t.insert("dog")
result = []
for i in t.traversal():
result.append(i)
assert sorted(result) == ["cat", "cats", "dog"]
示例5: test_traversal_with_apostrophe
# 需要导入模块: from trie import Trie [as 别名]
# 或者: from trie.Trie import traversal [as 别名]
def test_traversal_with_apostrophe():
"""Test traversal on trie with apostrophe."""
from trie import Trie
word_list = []
trie = Trie()
token1 = "blade's"
token2 = "fortune's"
trie.insert(token1)
trie.insert(token2)
for word in trie.traversal(start=trie.container):
word_list.append(word)
assert token1 in word_list
assert token2 in word_list
示例6: test_traversal_on_similar
# 需要导入模块: from trie import Trie [as 别名]
# 或者: from trie.Trie import traversal [as 别名]
def test_traversal_on_similar():
"""Test traversal on trie with similar words."""
from trie import Trie
word_list = []
trie = Trie()
token1 = 'free'
token2 = 'freedom'
trie.insert(token1)
trie.insert(token2)
for word in trie.traversal(start=trie.container):
word_list.append(word)
assert token1 in word_list
assert token2 in word_list
示例7: test_single_apostrophe
# 需要导入模块: from trie import Trie [as 别名]
# 或者: from trie.Trie import traversal [as 别名]
def test_single_apostrophe():
from trie import Trie
single = Trie()
single.insert('don\'t')
assert [x for x in single.traversal()] == ['don\'t']
示例8: test_single_trie_traversal
# 需要导入模块: from trie import Trie [as 别名]
# 或者: from trie.Trie import traversal [as 别名]
def test_single_trie_traversal():
from trie import Trie
single = Trie()
single.insert('one')
assert [x for x in single.traversal()] == ['one']
示例9: test_empty_trie
# 需要导入模块: from trie import Trie [as 别名]
# 或者: from trie.Trie import traversal [as 别名]
def test_empty_trie():
from trie import Trie
empty = Trie()
assert [x for x in empty.traversal()] == []