TypeError: 'range' object does not support item assignment
TypeError: 'range' object does not support item assignment
I was looking at some python 2.x code and attempted to translate it to py 3.x but I'm stuck on this section. Could anyone clarify what is wrong?
import random
emails = {
"x": "[REDACTED]@hotmail.com",
"x2": "[REDACTED]@hotmail.com",
"x3": "[REDACTED]@hotmail.com"
}
people = emails.keys()
#generate a number for everyone
allocations = range(len(people))
random.shuffle(allocations)
This was the error given TypeError: 'range' object does not support item assignment
In Python 3, range returns a lazy sequence object - it does not return a list. There is no way to rearrange elements in a range object, so it cannot be shuffled.
Convert it to a list before shuffling.
allocations = list(range(len(people)))
TypeError: 'range' object does not support item assignment的更多相关文章
- TypeError: 'range' object does not support item assignment处理方法
vectorsum.py#!/usr/bin/env/pythonimport sysfrom datetime import datetimeimport numpy as np # def num ...
- python 报错TypeError: 'range' object does not support item assignment,解决方法
贴问题 nums = range(5)#range is a built-in function that creates a list of integers print(nums)#prints ...
- python3中报错:TypeError: 'range' object doesn't support item deletion
1.源代码 以下代码执行时会报 range' object does not support item assignment 的错误,问题出现在第17行的runge(10): import unit ...
- TypeError: 'range' object doesn't support item deletion
python 是个逐步迭代开发的过程,他不是向下兼容的,更不是向上兼容,版本不一致,好端端的程序就是不能运行了. 下面是在python 2中能运行,在Python 3中不能运行的代码.其实也很简单.但 ...
- Python的字符串修改报错:TypeError: 'str' object does not support item assignment
Python中想修改字符串的最后一个字符,使用name[-1] = 'e'来实现,运行后报错. 报错内容是:TypeError: 'str' object does not support item ...
- TypeError: 'str' object does not support item assignment Python常见错误
1.string是一种不可变的数据类型 2.尝试使用 range()创建整数列 有时你想要得到一个有序的整数列表,所以 range() 看上去是生成此列表的不错方式. 需要记住 range() 返回的 ...
- Python:TypeError: 'range' object doesn't support item deletion
报错代码: dataIndex = range(m) del (dataIndex[randIndex]) 报错信息: 错误原因: python3 range返回的是range对象,不是数组对象 解决 ...
- python TypeError: 'str' object does not support item assignment”
想替换string里的空格,遍历替换提示如题错误,查询得知string类型不可更改 import string s = "2013/2/12" b = s.replace('/', ...
- TypeError: '_io.TextIOWrapper' object does not support item assignment
纯小白 遇到的细节问题: 报错 一开始看到这个傻逼了 TypeError: '_io.TextIOWrapper' object does not support item assignment 其实 ...
随机推荐
- SharePoint 2013 Newsfeed 没有出现的解决方法
按照这个guide配置mysite: http://technet.microsoft.com/en-us/library/ee624362(v=office.15).aspx 但是newsfeed页 ...
- awk实例
AWK-F 以XX为分割df -lh | grep boot | awk '{print $5}' | awk -F '%' '{print $1}'grep "bash" /et ...
- A1082. Read Number in Chinese
Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese ...
- MSSQL 转 ACCESS 在表格结构上应注意的
今天在把一个MSSQL数据库转为ACCESS发现了一些问题: 在MSSQL表格中的一个(标识)递增字段转到ACCESS后,变成了 “数字”类型,而不是“自动编号”. 而当在Access中,一个字段类型 ...
- typescript枚举,类型推论,类型兼容性,高级类型,Symbols(学习笔记非干货)
枚举部分 Enumeration part 使用枚举我们可以定义一些有名字的数字常量. 枚举通过 enum关键字来定义. Using enumerations, we can define some ...
- Linux就该这么学--第五期 学习笔记
第一节:基础 <Linux就该这么学>第二期视频 Linux就该这么学第5期第二节: ------------你的价值:你对公司做出的共享和你的不可替代性------------瑞尔系统R ...
- Java_myBatis_逆向工程
所谓逆向工程,就是根据数据库自动生成项目工程(包括了Interface.POJO.映射文件xml) 逆向工程包:https://github.com/wcyong/mybatisGeneratorCu ...
- MySQL邮件使用情况统计方法
邮件使用情况统计方法如下: ) AS domain, COUNT(DISTINCT [column_name]) AS mail_count, COUNT([column_name]) AS mail ...
- Django 2.0.1 官方文档翻译:编写你的第一个djang补丁(page 15)
编写你的第一个djang补丁(page 15) 介绍 有兴趣为社区做一些贡献?可能你发现了django中的一个你想修复的bug,或者你你想添加一个小小的功能. 回馈django就是解决你遇到的问题的最 ...
- postgresql行转列
问:怎么分页&&按条件&&按顺序&&姓名不重复查出数据? 答:其实就是行转列,那么,postgresql怎么进行转列呢,百度了下,大概有三种写法 写法1 ...