You are viewing a single comment's thread. Return to all comments →
Yep, so beautiful!
We can use collections.Counter to get a shorter solution
from collections import Counter def grams(contact): return [contact[:i] for i in range(1, len(contact)+1)] counter = Counter() n = int(input().strip()) for a0 in range(n): op, contact = input().strip().split(' ') if op == 'add': counter.update(grams(contact)) elif op == 'find': print(counter.get(contact, 0))
Seems like cookies are disabled on this browser, please enable them to open this website
Tries: Contacts
You are viewing a single comment's thread. Return to all comments →
Yep, so beautiful!
We can use collections.Counter to get a shorter solution