LoginSignup
0
1

More than 5 years have passed since last update.

random.shuffleでのエラー

Posted at

import random

a=range(10)
random.shuffle(a)
print(a)

のようなコードを入力すると次のようなエラーが出ます。

/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/bin/python3.6 /Users/*/PycharmProjects/demo4.py
Traceback (most recent call last):
File "/Users/
*/PycharmProjects/demo4.py", line 6, in
random.shuffle(a)
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/random.py", line 274, in shuffle
x[i], x[j] = x[j], x[i]
TypeError: 'range' object does not support item assignment

Process finished with exit code 1

random.randint(a, b)では正常に乱数が生成できているので、randomのimportには問題がないかとは思うのですが。
どなたかご助力お願いします。

0
1
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1