-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpython-default-dict.py
67 lines (42 loc) · 1.57 KB
/
python-default-dict.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from collections import defaultdict
def find_words(group_a, group_b):
d = defaultdict(list)
for i, word in enumerate(group_a, start=1):
d[word].append(i)
for word in group_b:
yield d.get(word, [-1])
def test_empty_list():
""" returns empty list """
group_a = []
group_b = []
assert list(find_words(group_a, group_b)) == []
def test_contains_all_one_group():
"""return all if all in one group"""
group_a = ['a', 'a', 'a', 'a', 'a']
group_b = ['a']
assert list(find_words(group_a, group_b)) == [[1, 2, 3, 4, 5]]
def test():
group_a = ['a', 'a', 'b', 'a', 'b']
group_b = ['a', 'b']
assert list(find_words(group_a, group_b)) == [[1, 2, 4], [3, 5]]
group_a = ['a', 'a', 'b', 'a', 'b']
group_b = ['b', 'a']
assert list(find_words(group_a, group_b)) == [[3, 5], [1, 2, 4]]
group_a = ['a', 'a', 'b', 'a', 'b']
group_b = ['a', 'a']
assert list(find_words(group_a, group_b)) == [[1, 2, 4], [1, 2, 4]]
def test_group_b_element_not_found():
group_a = ['a', 'a', 'b', 'a', 'b']
group_b = ['a', 'b', 'c']
assert list(find_words(group_a, group_b)) == [[1, 2, 4], [3, 5], [-1]]
def test_single_group():
"""returns all when one group specified"""
group_a = ['a', 'a', 'b', 'a', 'b']
group_b = ['a']
assert list(find_words(group_a, group_b)) == [[1, 2, 4]]
if __name__ == '__main__':
n, m = map(int, (input().split()))
group_a = [input() for _ in range(n)]
group_b = [input() for _ in range(m)]
for output in find_words(group_a, group_b):
print(*output)