You are viewing a single comment's thread. Return to all comments →
This is my solution for Python 3.5+ using dictionaries.
def contacts(queries): arr = defaultdict(list) r = [] def find(word): index = word[0] l = len(word) r = 0 for v in arr[index]: if v[:l] == word: r +=1 return r for q in queries: op, v = q if op == 'add': arr[v[0]].append(v) elif op == 'find': r.append(find(v)) return r
Seems like cookies are disabled on this browser, please enable them to open this website
Contacts
You are viewing a single comment's thread. Return to all comments →
This is my solution for Python 3.5+ using dictionaries.