回答編集履歴
1
追記
answer
CHANGED
@@ -5,4 +5,27 @@
|
|
5
5
|
[[1, 2]]
|
6
6
|
```
|
7
7
|
|
8
|
-
タプルのリストに置き換えて集合を取れば、論理和なども簡単に出せますね。
|
8
|
+
タプルのリストに置き換えて集合を取れば、論理和なども簡単に出せますね。
|
9
|
+
```Python
|
10
|
+
a = [[1, 2], [3, 4], [5, 6], [12, 13]]
|
11
|
+
b = [[1, 2], [7, 8], [9, 10]]
|
12
|
+
|
13
|
+
a_set = set(tuple(e) for e in a)
|
14
|
+
b_set = set(tuple(e) for e in b)
|
15
|
+
|
16
|
+
ab_and = [list(e) for e in a_set & b_set]
|
17
|
+
print(ab_and)
|
18
|
+
|
19
|
+
ab_or = [list(e) for e in a_set | b_set]
|
20
|
+
print(ab_or)
|
21
|
+
|
22
|
+
ab_xor = [list(e) for e in a_set ^ b_set]
|
23
|
+
print(ab_xor)
|
24
|
+
```
|
25
|
+
|
26
|
+
**実行結果** [Wandbox](https://wandbox.org/permlink/EHWvTaxfUEmlTugb)
|
27
|
+
```
|
28
|
+
[[1, 2]]
|
29
|
+
[[1, 2], [7, 8], [9, 10], [5, 6], [3, 4], [12, 13]]
|
30
|
+
[[7, 8], [5, 6], [12, 13], [9, 10], [3, 4]]
|
31
|
+
```
|