You are viewing a single comment's thread. Return to all comments →
Creating a defaultdict makes this one pretty easy.
` from collections import defaultdict
def matchingStrings(stringList, queries): hm = defaultdict(int) for key in stringList: hm[key] += 1 return [hm[key] for key in queries] `
Seems like cookies are disabled on this browser, please enable them to open this website
Sparse Arrays
You are viewing a single comment's thread. Return to all comments →
Creating a defaultdict makes this one pretty easy.
` from collections import defaultdict
def matchingStrings(stringList, queries): hm = defaultdict(int) for key in stringList: hm[key] += 1 return [hm[key] for key in queries] `