Skip to content

Instantly share code, notes, and snippets.

Last active July 2, 2021 18:41
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
An implementation of a trie in python using defaultdict and recursion
from collections import defaultdict
def node():
return defaultdict(node)
def word_exists(word, node):
if not word:
return None in node
return word_exists(word[1:], node[word[0]])
def add_word(word, node):
if not word:
# terminal letter of the word
add_word(word[1:], node[word[0]])
Copy link

crlane commented Dec 15, 2019

Looks like you're missing ]) on line 9


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment