回答編集履歴

1

追記

2018/09/06 08:38

投稿

LouiS0616
LouiS0616

スコア35660

test CHANGED
@@ -13,3 +13,49 @@
13
13
 
14
14
 
15
15
  タプルのリストに置き換えて集合を取れば、論理和なども簡単に出せますね。
16
+
17
+ ```Python
18
+
19
+ a = [[1, 2], [3, 4], [5, 6], [12, 13]]
20
+
21
+ b = [[1, 2], [7, 8], [9, 10]]
22
+
23
+
24
+
25
+ a_set = set(tuple(e) for e in a)
26
+
27
+ b_set = set(tuple(e) for e in b)
28
+
29
+
30
+
31
+ ab_and = [list(e) for e in a_set & b_set]
32
+
33
+ print(ab_and)
34
+
35
+
36
+
37
+ ab_or = [list(e) for e in a_set | b_set]
38
+
39
+ print(ab_or)
40
+
41
+
42
+
43
+ ab_xor = [list(e) for e in a_set ^ b_set]
44
+
45
+ print(ab_xor)
46
+
47
+ ```
48
+
49
+
50
+
51
+ **実行結果** [Wandbox](https://wandbox.org/permlink/EHWvTaxfUEmlTugb)
52
+
53
+ ```
54
+
55
+ [[1, 2]]
56
+
57
+ [[1, 2], [7, 8], [9, 10], [5, 6], [3, 4], [12, 13]]
58
+
59
+ [[7, 8], [5, 6], [12, 13], [9, 10], [3, 4]]
60
+
61
+ ```