Created
April 28, 2010 23:56
-
-
Save anfedorov/382921 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
from collections import defaultdict | |
def new_trie(): | |
t = defaultdict() | |
t.default_factory = lambda: [new_trie(), 0] | |
return t | |
def insert(t, s): | |
for c in s: | |
t = t[c][0] | |
t[c][1] += 1 | |
return t[c][1] | |
def lookup(t, s): | |
for c in s: | |
t = t[c][0] | |
return t[c][1] | |
t = new_trie() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment