-
Notifications
You must be signed in to change notification settings - Fork 0
/
sparseArrays.py
43 lines (31 loc) · 1.06 KB
/
sparseArrays.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/python3
# ALDO FUSTER TURPIN
def findSuffix(queryString, count_dict):
count = count_dict.get(queryString, 0)
return count
if __name__ == '__main__':
# number of strings that the collection will have
strings_count = int(input())
# the string collection
strings = []
# counter_dictionary
count_dict = {}
for _ in range(strings_count):
strings_item = input()
if (strings_item in count_dict):
count_dict[strings_item] = count_dict[strings_item] + 1
# first appearance of the element:
else:
count_dict[strings_item] = 1
strings.append(strings_item)
# print("The map:-> ", end="")
# for k, v in count_dict.items():
# print("key:", k, ", value:", v)
# number of querys that will be made
q = int(input())
for q_itr in range(q):
# string that we want to look for
queryString = input()
# "res" is the number of times queryString appears in collections
res = findSuffix(queryString, count_dict)
print((str(res)))