当前位置: 首页>>代码示例>>Python>>正文


Python Trie.traversal方法代码示例

本文整理汇总了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']
开发者ID:wohlfea,项目名称:data-structures2,代码行数:9,代码来源:test_trie.py

示例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 == []
开发者ID:muniri92,项目名称:Data-Structures-2.0,代码行数:10,代码来源:test_trie.py

示例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 == []
开发者ID:jmcclena94,项目名称:data-structures,代码行数:10,代码来源:test_trie.py

示例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"]
开发者ID:muniri92,项目名称:Data-Structures-2.0,代码行数:13,代码来源:test_trie.py

示例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
开发者ID:jmcclena94,项目名称:data-structures,代码行数:15,代码来源:test_trie.py

示例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
开发者ID:jmcclena94,项目名称:data-structures,代码行数:15,代码来源:test_trie.py

示例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']
开发者ID:wohlfea,项目名称:data-structures2,代码行数:7,代码来源:test_trie.py

示例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']
开发者ID:wohlfea,项目名称:data-structures2,代码行数:7,代码来源:test_trie.py

示例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()] == []
开发者ID:wohlfea,项目名称:data-structures2,代码行数:6,代码来源:test_trie.py


注:本文中的trie.Trie.traversal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。