回答編集履歴
2
出力追記
answer
CHANGED
@@ -22,6 +22,11 @@
|
|
22
22
|
result.append(sentence[id_])
|
23
23
|
print(result)
|
24
24
|
```
|
25
|
+
```
|
26
|
+
['learning', 'deep', 'not']
|
27
|
+
[2, 4, 5]
|
28
|
+
['not', 'deep', 'learning']
|
29
|
+
```
|
25
30
|
|
26
31
|
愚直にchoiceして削除してリストに追加してソートしてみました。
|
27
32
|
```Python3
|
1
仕様変更に対応
answer
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
+
回答している間に仕様変わったので追記。
|
1
2
|
愚直にchoiceして削除してリストに追加してソートしてみました。
|
3
|
+
途中indexリストで順番を保持し最後にindexから単語を取得し出力。
|
2
4
|
|
3
5
|
```Python3
|
4
6
|
import random as rd
|
@@ -6,6 +8,28 @@
|
|
6
8
|
ch = rd.choice(src)
|
7
9
|
src.remove(ch)
|
8
10
|
return ch
|
11
|
+
sentence = ["I","can","not","understand","deep","learning"]
|
12
|
+
src = sentence.copy()
|
13
|
+
ch_lst = [f() for _ in range(3)]
|
14
|
+
print(ch_lst)
|
15
|
+
id_lst = []
|
16
|
+
for ch in ch_lst:
|
17
|
+
id_lst.append(sentence.index(ch))
|
18
|
+
id_lst.sort()
|
19
|
+
print(id_lst)
|
20
|
+
result = []
|
21
|
+
for id_ in id_lst:
|
22
|
+
result.append(sentence[id_])
|
23
|
+
print(result)
|
24
|
+
```
|
25
|
+
|
26
|
+
愚直にchoiceして削除してリストに追加してソートしてみました。
|
27
|
+
```Python3
|
28
|
+
import random as rd
|
29
|
+
def f():
|
30
|
+
ch = rd.choice(src)
|
31
|
+
src.remove(ch)
|
32
|
+
return ch
|
9
33
|
src = ["a","b","c","d","e","f","g","h","i","j"]
|
10
34
|
ch_lst = [f() for _ in range(3)]
|
11
35
|
ch_lst.sort()
|