Skip to content

A basic implementation of word dictionary using the Trie data structure

License

Notifications You must be signed in to change notification settings

tharunsuresh-code/pytrie

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

pytrie

A basic implementation of word dictionary using the Trie data structure in Python 3.

A trie (derived from retrieval) is a multiway tree data structure used for storing strings over an alphabet. It is used to store a large amount of strings. The pattern matching can be done efficiently using tries.

To clone the repo:

git clone https://github.com/tharunsuresh-code/pytrie.git

Usage

Create a new Trie to use as a word dictionary:

from pytrie import Trie

trie = Trie()
trie.addWord("hello")
trie.addWord("world")
trie.addWord("Harry")
trie.addWord("Potter")

Now you can query the Trie for any string:

>>> trie.search("hello")
True
>>> trie.search("world")
True
>>> trie.search("harry")
False
>>> trie.search("Harry")
True

Wildcard Search

You can also search for words using wildcard . character. It replaces for one single character:

>>> trie.search("H.rr.")
True
>>> trie.search("P...")
False
>>> trie.search("P....r")
True

References

Docs are inspired from PyTrie and datrie. Trie definition from geeksforgeeks.

License

Licensed under MIT.

About

A basic implementation of word dictionary using the Trie data structure

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages