Skip to content

Instantly share code, notes, and snippets.

@kdeloach
Created July 3, 2017 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kdeloach/39852bf6162acabc13bab091e1be54e5 to your computer and use it in GitHub Desktop.
Save kdeloach/39852bf6162acabc13bab091e1be54e5 to your computer and use it in GitHub Desktop.
def make_trie(rows):
trie = {}
for row in rows:
key = row[0]
value = row[1]
trie_append(trie, key, value)
return trie
def trie_append(node, key, value):
for c in key:
if c not in node:
node[c] = dict()
node = node[c]
node['value'] = value
def trie_find(node, key):
for c in key:
if c not in node:
return False
node = node[c]
return node['value']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment