Created
July 3, 2017 02:09
-
-
Save kdeloach/39852bf6162acabc13bab091e1be54e5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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