回答編集履歴

1

edit

2018/02/21 14:28

投稿

mkgrei
mkgrei

スコア8560

test CHANGED
@@ -7,3 +7,45 @@
7
7
 
8
8
 
9
9
  何度も検索するのであれば、最初にそのための辞書を作ってからの方が速くなります。
10
+
11
+
12
+
13
+ ---
14
+
15
+
16
+
17
+ 衝突回避版。
18
+
19
+
20
+
21
+ ```python
22
+
23
+ test_dict = {
24
+
25
+ "A":["A","B","C"],
26
+
27
+ "B":["B","C","D"],
28
+
29
+ "X":["X","Y","Z"],
30
+
31
+ }
32
+
33
+
34
+
35
+ test_dict_1 = {}
36
+
37
+ for k, v in test_dict.items():
38
+
39
+ if v[1] in test_dict_1:
40
+
41
+ test_dict_1[v[1]].append(k)
42
+
43
+ else:
44
+
45
+ test_dict_1[v[1]] = [k]
46
+
47
+
48
+
49
+ print([test_dict[k] for k in test_dict_1['B']])
50
+
51
+ ```