-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefaultDict.py
executable file
·51 lines (41 loc) · 1.27 KB
/
defaultDict.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
43
44
45
46
47
48
49
50
51
#!/bin/env python3
"""
defaultdict tool is a containter in the collections class of Python.
It is similar to the usual dictionary (dict) container, but it has one
difference: The value fields' data type is specified upon initialization.
INPUT: 1 + n + m lines
int n and m
next n lines:
words belonging to group A
next m lines:
words belonging to group B
For each group B word,
find position in the group A list
pos1 pos2 pos3
OUTPUT: m lines
ea. line should contain the positions of the occurences of
group B word in the group A list separated by spaces.
Print the indices of ea. occurrence of m in group A.
If it does not appear, print -1.
"""
import collections
if __name__ == '__main__':
"""
Read in n and m
the number of expected words in group A and
group B.
Create a dictionary of lists for the positions.
While reading in group A note the positions,
(zero index + 1) into the dictionary.
While reading in group B look for the word,
and print the positions.
"""
n, m = map(int, input().split())
positions = collections.defaultdict(list)
for i in range(n):
word = input()
positions[word].append(i + 1)
for i in range(m):
word = input()
p = positions.get(word, -1)
print(*p)