Skip to content

Instantly share code, notes, and snippets.

@seve
Last active February 22, 2019 00:45
Show Gist options
  • Save seve/4ab7b739a2ed95d3857f53fab524273f to your computer and use it in GitHub Desktop.
Save seve/4ab7b739a2ed95d3857f53fab524273f to your computer and use it in GitHub Desktop.
class MyTrie(dict):
def __init__(self, word_list=None):
super(MyTrie, self).__init__()
self.id = 0
# the charcter, a unique id, end charcter in a word
self.root = ('', self.id, False)
self[self.root] = []
self.id += 1
if word_list is not None:
for word in word_list:
self.add_word(word)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment