Skip to content

Instantly share code, notes, and snippets.

Last active Feb 13, 2017
What would you like to do?
actions = int(raw_input())
def node():
return [0, {}]
contacts = node()
for a in xrange(actions):
action, word = map(str, raw_input().split())
cont = contacts
if action == 'add':
cont[0] += 1
for c in word:
if not cont[1].get(c):
cont[1][c] = node()
cont = cont[1].get(c)
cont[0] += 1
if action == 'find':
for c in word:
cont = cont[1].get(c)
if not cont:
print cont[0] if cont else 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment