Пример #1
0
#!/usr/bin/env python3

from trie import Trie

trie = Trie()

trie.add_string("hello")
trie.add_string("happy")
trie.add_string("cat")
trie.add_string("chunnu")
trie.add_string("call")

#words = trie.get_node("h")
print(trie.get_matching_words("call"))

print(trie.get_full_words())

Пример #2
0
import sys
from trie import Trie
from common import *
import string

f = open(sys.argv[1], 'r')
t = Trie()

table = str.maketrans({key: None for key in string.punctuation})

words = file_to_words(f)
[t.add_string(word) for word in words]

print(t.gv_serialize())
from trie import Trie

strings = ['apple', 'ape', 'or', 'orange', 'oppa']

t = Trie()

for s in strings:
    t.add_string(s)

print('// to compile this try dot trie.dot -T png -o trie.png\n')
print('// don\'t forget to pipe this to a file :)\n')
print(t.gv_serialize())