Created
September 5, 2018 06:02
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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