IndexError:list assignment index out of range
L=[] L[0]=2
L[1]=3
报错:IndexError: list assignment index out of range,列表超过限制
一种情况是:list[index]的index超出范围
另一种情况是:list是一个空的,没有一个元素,进行list[0]就会出现错误!
本例是第二种情况——声明了一个List对象,想通过List[index]=value的方式向其中添加元素
解决方法:
①用append的方法向其中添加元素
L.append(2)
L.append(3)
②不用List,改用Dict类型
很简单,把[]换成{}即可
L=[] => L={}
不过这时候L就不是List了,而是一个Dict字典对象
IndexError:list assignment index out of range的更多相关文章
- python数组中数据位置交换 -- IndexError: list assignment index out of range
代码: t = [-10,-3,-100,-1000,-239,1] # 交换 -10和1的位置 t[5], t[t[5]-1] = t[t[5]-1], t[5] 报错: IndexError: l ...
- 程序中出现list assignment index out of range的解决方法
class stack: def __init__(self): self.num = 0 self.elem=[] def isEmoty(self): if self.num == 0: prin ...
- Python常见错误:IndexError: list index out of range
用python写脚本查询字典时,在遍历字典时循环到某一项时老是报错 出现这种错误有两种情况: 第1种可能情况 list[index]index超出范围 第2种可能情况 list是空值就会出现 In ...
- python报错IndexError: list index out of range
今天写个ping vpn的python脚本,报错IndexError: list index out of range 最后查看是python读取文件中出现空格 去掉空格即可
- pyinstaller 将.py生成.exe ----报错 “IndexError: tuple index out of range”
pyinstaller将py打包为exe文件,用pysintaller居然报错 File "c:\anaconda3\lib\site-packages\PyInstaller\depend ...
- IndexError:string index out of range
IndexError:string index out of range 出现在下标越界的情况,如 item[1],可能为空的时候下标就会越界
- 在数组添加元素时报错:IndexError: list index out of range
今天第一次发随笔还有许多不足之处,欢迎评论!!! 最近在写一个成语接龙的小游戏,结果在数组添加元素时报错:IndexError: list index out of range 源码: import ...
- mac安装MySQLdb:IndexError: string index out of range
使用mac安装MySQLdb的时候出现string index out of range 大概的错误是这样的: 然后尝试手动安装,我下载了包后,依然出现这个错误. 于是百度了下: https://ww ...
- ChIP-seq Peak caller MACS index out of range问题解决
使用MACS1.4 进行peak calling的时候发现一个比较奇怪的问题: 我的某些文件无法被MACS1.4 进行peak calling,出现如下的信息: Traceback (most rec ...
随机推荐
- linux判断物理CPU,逻辑CPU和CPU核数
① 物理CPU 实际Server中插槽上的CPU个数 物理cpu数量,可以数不重复的 physical id 有几个 ② 逻辑CPU Linux用户对 /proc/cpuinfo 这个文件肯定不陌生. ...
- django之集成阿里云通信(发送手机短信验证码)
python3 + django2.0 集成 "阿里云通信" 服务: (SDK文档地址:https://help.aliyun.com/document_detail/55491. ...
- .NET 5.0 Docker 镜像 错误修复方法
在给eshopondapr 打镜像的时候碰到了3个错误 1.restore: Received an unexpected EOF or 0 bytes from the transport stre ...
- NoSQL之Redis配置与优化
NoSQL之Redis配置与优化 目录 NoSQL之Redis配置与优化 一.关系数据库和非关系数据库 1. 关系型数据库 2. 非关系型数据库 3. 非关系型数据库产生背景 4. 关系型数据库和非关 ...
- Ubuntu 20.04.3 LTS + Intel Realsense 400系列
Ubuntu 如何查看当前Ubuntu系统的版本,以及看自己的系统是否为LTS版本 lsb_release -a 如何查看Ubuntu系统的Linux系统版本,和GCC版本 cat /proc/ver ...
- redis(二)-----redis基本数据类型之字符串
Redis的全称是REmote Dictionary Server,它主要提供了5种数据结构:字符串.哈希.列表.集合.有序集合,同时在字符串的基础之上演变 出了位图(Bitmaps)和HyperLo ...
- Solution -「多校联训」最大面积
\(\mathcal{Description}\) Link. 平面上有 \(n\) 个点 \(A_{1..n}\),\(q\) 次询问,每次给出点 \(P\),求 \[\max_{1\le ...
- Solution -「JSOI2008」「洛谷 P4208」最小生成树计数
\(\mathcal{Description}\) link. 给定带权简单无向图,求其最小生成树个数. 顶点数 \(n\le10^2\),边数 \(m\le10^3\),相同边权的边数不 ...
- 微服务从代码到k8s部署应有尽有系列(六、订单服务)
我们用一个系列来讲解从需求到上线.从代码到k8s部署.从日志到监控等各个方面的微服务完整实践. 整个项目使用了go-zero开发的微服务,基本包含了go-zero以及相关go-zero作者开发的一些中 ...
- SIMD编码/解码
在看SEAL库和HElib库中经常在编码中碰到打包(batch)技术,另外还提到了SIMD编码技术,有点困惑,编码.打包.SIMD到底有什么关系? 编码 在CKKS方案中,因为明文空间在复数域上,简单 ...