回答編集履歴
1
追記
test
CHANGED
@@ -29,3 +29,37 @@
|
|
29
29
|
[12, 1, 6, 14, 2, 13, 15, 3, 9, 11, 5, 10, 4, 7, 8, 0]
|
30
30
|
|
31
31
|
```
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
## 追記
|
36
|
+
|
37
|
+
sampleの結果を変数に入れてあげると良いと思われます。num_listそのものを並び替えたいのであれば、shuffleを使うと良いです。以下が参考になると思います。
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
```python
|
42
|
+
|
43
|
+
>>> from random import sample, shuffle
|
44
|
+
|
45
|
+
>>> num_list = list(range(16))
|
46
|
+
|
47
|
+
>>> rnd_num_list = sample(num_list, len(num_list))
|
48
|
+
|
49
|
+
>>> rnd_num_list
|
50
|
+
|
51
|
+
[3, 0, 10, 14, 8, 7, 11, 15, 6, 4, 9, 5, 13, 12, 2, 1]
|
52
|
+
|
53
|
+
>>> num_list
|
54
|
+
|
55
|
+
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
|
56
|
+
|
57
|
+
>>> shuffle(num_list)
|
58
|
+
|
59
|
+
>>> num_list
|
60
|
+
|
61
|
+
[0, 3, 9, 14, 5, 4, 6, 12, 13, 11, 8, 15, 7, 2, 1, 10]
|
62
|
+
|
63
|
+
```
|
64
|
+
|
65
|
+
[FYI] [https://note.nkmk.me/python-random-shuffle/](https://note.nkmk.me/python-random-shuffle/)
|