回答編集履歴
1
質問の変更に伴うコード修正
answer
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
もとのリストの要素数にもよりますが、
|
2
2
|
先に ``itertools.combinations()`` にて全組み合わせのリストを作成し、``random.choice()``にてその中から1つ選択するという方法はいかがでしょうか
|
3
3
|
|
4
|
-
```
|
4
|
+
```Python
|
5
5
|
import itertools
|
6
6
|
import random
|
7
7
|
|
8
|
-
|
8
|
+
sentence = ["I","can","not","understand","deep","learning"]
|
9
|
-
ret = random.choice(list(itertools.combinations(
|
9
|
+
ret = random.choice(list(itertools.combinations(sentence, 3)))
|
10
10
|
```
|