回答編集履歴
3
表現の修正
test
CHANGED
@@ -16,9 +16,9 @@
|
|
16
16
|
|
17
17
|
|
18
18
|
|
19
|
-
**
|
19
|
+
**明らかなバグ**
|
20
20
|
|
21
|
-
b_pairs
|
21
|
+
b_pairsを毎回上書きして、前の周回のデータを吹っ飛ばしてます。
|
22
22
|
|
23
23
|
|
24
24
|
|
2
修正
test
CHANGED
@@ -44,7 +44,9 @@
|
|
44
44
|
|
45
45
|
b_pairs += list(itertools.combinations(b, i))
|
46
46
|
|
47
|
-
|
47
|
+
# 単に b_pairs += itertools.combinations(b, i) でも可
|
48
|
+
|
49
|
+
|
48
50
|
|
49
51
|
print(b_pairs)
|
50
52
|
|
1
追記
test
CHANGED
@@ -59,3 +59,29 @@
|
|
59
59
|
[(1, 2), (1, 3), (2, 3), (1, 2, 3)]
|
60
60
|
|
61
61
|
```
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
おまけ
|
66
|
+
|
67
|
+
---
|
68
|
+
|
69
|
+
こういうときは[more-itertools](https://more-itertools.readthedocs.io/en/stable/index.html)が便利です。
|
70
|
+
|
71
|
+
```Python
|
72
|
+
|
73
|
+
>>> list(more_itertools.powerset(b))
|
74
|
+
|
75
|
+
[(), (1,), (2,), (3,), (1, 2), (1, 3), (2, 3), (1, 2, 3)]
|
76
|
+
|
77
|
+
>>> [s for s in more_itertools.powerset(b)]
|
78
|
+
|
79
|
+
[(), (1,), (2,), (3,), (1, 2), (1, 3), (2, 3), (1, 2, 3)]
|
80
|
+
|
81
|
+
>>>
|
82
|
+
|
83
|
+
>>> [s for s in more_itertools.powerset(b) if len(s) >= 2]
|
84
|
+
|
85
|
+
[(1, 2), (1, 3), (2, 3), (1, 2, 3)]
|
86
|
+
|
87
|
+
```
|