python错误之RuntimeError: dictionary changed size during iteration
pythonn报错信息:
C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\python.exe C:/Users/Administrator/PycharmProjects/pythondemo/maptest.py
Traceback (most recent call last):
File "C:/Users/Administrator/PycharmProjects/pythondemo/maptest.py", line 5, in <module>
for line in maps.keys():
RuntimeError: dictionary changed size during iteration python2中实现遍历的同时删除字典中的元素;python3中运行报错信息:
C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\python.exe C:/Users/Administrator/PycharmProjects/pythondemo/maptest.py
Traceback (most recent call last):
File "C:/Users/Administrator/PycharmProjects/pythondemo/maptest.py", line 5, in <module>
for line in maps.keys():
RuntimeError: dictionary changed size during iteration
# maps = {1:"李明",2:"丹尼"}
# for line in maps.keys():
# if(line == 2):
# maps.pop(line)
# print(maps)
python3中实现遍历的同时删除字典中的元素
maps = {1:"李明",2:"丹尼"}
for line in list(maps.keys()):
if(line == 2):
maps.pop(line)
print(maps)
python错误之RuntimeError: dictionary changed size during iteration的更多相关文章
- python 报错RuntimeError: dictionary changed size during iteration
a = {':0} for b in list(a.keys()): if a[b] == 0: del a[b] print(a) 报错是因为在字典迭代期间改变字典大小 我们可以通过取出字典的键值, ...
- 循环字典进行操作时出现:RuntimeError: dictionary changed size during iteration的解决方案
在做对员工信息增删改查这个作业时,有一个需求是通过用户输入的id删除用户信息.我把用户信息从文件提取出来储存在了字典里,其中key是用户id,value是用户的其他信息.在循环字典的时候,当用户id和 ...
- 迭代var()内置函数的时候出现RuntimeError: dictionary changed size during iteration的解决办法
下午看了Mr Seven的教学视频,其中有一段讲全局变量的视频,迭代输出全局变量的时候报错了. 视频中的做法: for k,v in vars().items(): print(k) 打印结果 for ...
- Python面试题目之(针对dict或者set数据类型)边遍历 边修改 报错dictionary changed size during iteration
# result 是一个字典, 把里面属性值是None的属性删除 for key in result: if not result[key]: del result[key] continue 但是报 ...
- python : dictionary changed size during iteration
1. 错误方式 #这里初始化一个dict >>> d = {'a':1, 'b':0, 'c':1, 'd':0} #本意是遍历dict,发现元素的值是0的话,就删掉 >> ...
- 编程中遇到的Python错误和解决方法汇总整理
这篇文章主要介绍了自己编程中遇到的Python错误和解决方法汇总整理,本文收集整理了较多的案例,需要的朋友可以参考下 开个贴,用于记录平时经常碰到的Python的错误同时对导致错误的原因进行分析, ...
- Python 3.5 RuntimeError: can't start new thread
/*********************************************************************** * Python 3.5 RuntimeError: ...
- paip.python错误解决24
paip.python错误解决 作者Attilax 艾龙, EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog.csdn.net/attilax ...
- paip.python错误解决23
paip.python错误解决 作者Attilax 艾龙, EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog.csdn.net/attilax ...
随机推荐
- Sqoop hive导出到mysql[转]
通过Sqoop将Hive表数据导入到MySQL通常有两种情况. 第一种是将hive上某张表的全部数据导入到mysql对应的表中. 第二种是将hive上某张表中的部分数据导入到mysql对应的表中. 两 ...
- linux从用户组中删除某用户
1. 从wheel组中删除 test用户 gpasswd wheel -d test 2. 给 目录赋予 其他组上传文件的权限 chmod a+w test
- IOS下WEBVIEW 的javascript数组与json定义 及交互
最近在折腾IOS新闻浏览客户端,当中需要用到webview传递JSON数据到IOS上,然后在IOS上解析.刚入门IOS不久,看了不少的书,但都是囫囵吞枣.在开发过程中,遇到不少问题.开发环境mac m ...
- 随滚动条滚动,动态修改元素class
页面某块内容当页面滚动时,固定在浏览器的一个位置 其实就是改变了便签的class,修改了css属性设置position: fixed:fixed属性可以让便签固定在浏览器某一位置(记得引用jquery ...
- C++类定义 常量定义
#include "stdafx.h"#include "iostream" using namespace std; class MyClass{ int _ ...
- 使用cygwin注意事项二
使用cygwin时,一定要区分当前运行的是cygwin下的进程还是windows下的进程,如:使用vim, 假如cygwin下没安装vim, windows下安装了,那么你运行的就是windows下的 ...
- 在CentOs6.x 安装Cx_oracle5.x
Setting up anything Oracle related is a huge pain. After hunting the web for info with minimal succe ...
- linux安装flume及问题
验证是否安装成功: [root@master conf]# /usr/local/src/apache-flume-1.6.0-bin/bin/flume-ng versionError: Could ...
- 从MySQL获取数据
安装 PM> install-package newtonsoft.json PM> install-package mysql.data string connectionString ...
- C# HTML解析工具HtmlAgilityPack使用实例(一)
一.生成HTML字符串 //生成DOM字符串结构 HtmlNode container = HtmlNode.CreateNode("<div />"); HtmlNo ...