datrie is a Python module that provides super-fast, efficiently stored Trie for Python (2.x and 3.x). Uses libdatrie.
pip install datrie
Create a new trie capable of storing lower-case ascii letters:
>>> import string
>>> import datrie
>>> trie = datrie.new(string.ascii_lowercase)
trie variable is a dict-like object that can have unicode keys of certain ranges and integer values.
In addition to implementing the mapping interface, tries facilitate finding the items for a given prefix, and vice versa, finding the items whose keys are prefixes of a given string. As a common special case, finding the longest-prefix item is also supported.
· keys must be unicode (no implicit conversion for byte strings under Python 2.x, sorry);
· values must be integers 0
What's New in This Release: [ read full changelog ]
· longest_prefix and longest_prefix_item methods are fixed;
· datrie is rebuilt with Cython 0.18;
· misleading benchmark results in README are fixed;
· State._walk is renamed to State.walk_char.