成功解决random.py"之TypeError: 'range' object does not support item assignment 解决问题

简介: 成功解决random.py"之TypeError: 'range' object does not support item assignment

解决问题

 

File "F:\Program Files\Python\Python36\lib\random.py", line 275, in shuffle

  x[i], x[j] = x[j], x[i]

 

 

TypeError: 'range' object does not support item assignment

 

 

解决思路

 

random.shuffle(object)    ,其中object对象的类型必须是list的类型

 

 

解决方法

 

object参数的输出必须是list的格式。

因为,Python2Python3range()函数的用法不一致,在Python2中,输出的是list类型,而Python3中输出的是range类型。

所以,需要强制转换!

 

解决法:

<pre name="code" class="python">  

trainingSet = range(object);

替换为

trainingSet = list(range(object));

 

完美解决,大功告成!

相关文章
Vue3接口数据报错TypeError: target must be an object
Vue3接口数据报错TypeError: target must be an object
1439 0
Python错误 TypeError: ‘NoneType‘ object is not subscriptable解决方案汇总
Python错误 TypeError: ‘NoneType‘ object is not subscriptable解决方案汇总
|
6月前
|
存储 JSON JavaScript
【Python】已完美解决:TypeError: the JSON object must be str, bytes or bytearray, not dict
【Python】已完美解决:TypeError: the JSON object must be str, bytes or bytearray, not dict
347 1
|
8月前
|
JSON 数据格式
解决报错TypeError: Converting circular structure to JSON --> starting at object with constructor
解决报错TypeError: Converting circular structure to JSON --> starting at object with constructor
|
6月前
|
JSON 前端开发 数据格式
【Python】已解决:TypeError: Object of type JpegImageFile is not JSON serializable
【Python】已解决:TypeError: Object of type JpegImageFile is not JSON serializable
118 0
|
6月前
|
开发者 Python
【Python】已解决:TypeError: descriptor ‘index‘ for ‘list‘ objects doesn‘t apply to a ‘str‘ object
【Python】已解决:TypeError: descriptor ‘index‘ for ‘list‘ objects doesn‘t apply to a ‘str‘ object
162 0
|
6月前
|
开发者 Python
【Python】已解决:TypeError: a bytes-like object is required, not ‘int’
【Python】已解决:TypeError: a bytes-like object is required, not ‘int’
295 0
|
8月前
|
JSON 数据格式 Python
TypeError the JSON object must be str, bytes or bytearray, not ‘list‘
TypeError the JSON object must be str, bytes or bytearray, not ‘list‘
195 1
|
8月前
|
Python
完美解决丨+# TypeError: ‘dict_keys‘ object does not support indexing
完美解决丨+# TypeError: ‘dict_keys‘ object does not support indexing
|
机器学习/深度学习 自然语言处理 数据可视化
简单的知识图谱可视化+绘制nx.Graph()时报错TypeError: ‘_AxesStack‘ object is not callable
简单的知识图谱可视化+绘制nx.Graph()时报错TypeError: ‘_AxesStack‘ object is not callable
213 0