Skip to content

Instantly share code, notes, and snippets.

@hansrajdas
Created September 5, 2018 06:02
Show Gist options
  • Save hansrajdas/69cf02215c30c08394949bf5bb0806d7 to your computer and use it in GitHub Desktop.
Save hansrajdas/69cf02215c30c08394949bf5bb0806d7 to your computer and use it in GitHub Desktop.
Given list of N strings and Q queries, count how many times query strings occurs in N strings.
def find_string():
N = int(raw_input())
words = {}
for i in range(0, N):
w = raw_input()
if w in words:
words[w] += 1
else:
words[w] = 1
Q = int(raw_input())
for i in range(0, Q):
w = raw_input()
print words.get(w, 0)
if __name__ == '__main__':
find_string()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment