teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

質問の変更に伴うコード修正

2018/09/25 23:27

投稿

magichan
magichan

スコア15898

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
- lst = ["a","b","c","d","e","f","g","h","i","j"]
8
+ sentence = ["I","can","not","understand","deep","learning"]
9
- ret = random.choice(list(itertools.combinations(lst, 3)))
9
+ ret = random.choice(list(itertools.combinations(sentence, 3)))
10
10
  ```