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的更多相关文章

  1. python 报错RuntimeError: dictionary changed size during iteration

    a = {':0} for b in list(a.keys()): if a[b] == 0: del a[b] print(a) 报错是因为在字典迭代期间改变字典大小 我们可以通过取出字典的键值, ...

  2. 循环字典进行操作时出现:RuntimeError: dictionary changed size during iteration的解决方案

    在做对员工信息增删改查这个作业时,有一个需求是通过用户输入的id删除用户信息.我把用户信息从文件提取出来储存在了字典里,其中key是用户id,value是用户的其他信息.在循环字典的时候,当用户id和 ...

  3. 迭代var()内置函数的时候出现RuntimeError: dictionary changed size during iteration的解决办法

    下午看了Mr Seven的教学视频,其中有一段讲全局变量的视频,迭代输出全局变量的时候报错了. 视频中的做法: for k,v in vars().items(): print(k) 打印结果 for ...

  4. Python面试题目之(针对dict或者set数据类型)边遍历 边修改 报错dictionary changed size during iteration

    # result 是一个字典, 把里面属性值是None的属性删除 for key in result: if not result[key]: del result[key] continue 但是报 ...

  5. python : dictionary changed size during iteration

    1. 错误方式 #这里初始化一个dict >>> d = {'a':1, 'b':0, 'c':1, 'd':0} #本意是遍历dict,发现元素的值是0的话,就删掉 >> ...

  6. 编程中遇到的Python错误和解决方法汇总整理

    这篇文章主要介绍了自己编程中遇到的Python错误和解决方法汇总整理,本文收集整理了较多的案例,需要的朋友可以参考下   开个贴,用于记录平时经常碰到的Python的错误同时对导致错误的原因进行分析, ...

  7. Python 3.5 RuntimeError: can't start new thread

    /*********************************************************************** * Python 3.5 RuntimeError: ...

  8. paip.python错误解决24

    paip.python错误解决 作者Attilax 艾龙, EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog.csdn.net/attilax ...

  9. paip.python错误解决23

    paip.python错误解决 作者Attilax 艾龙, EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog.csdn.net/attilax ...

随机推荐

  1. leetcode leetcode 783. Minimum Distance Between BST Nodes

    Given a Binary Search Tree (BST) with the root node root, return the minimum difference between the ...

  2. hihocoder #1094 : Lost in the City微软苏州校招笔试 12月27日 (建图不大【暴力枚举】 子图的4种形态 1Y )

    #1094 : Lost in the City 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi gets lost in the city. He ...

  3. codeforces Codeforces Round #273 (Div. 2) 478B

    B. Random Teams time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  4. Codeforces Round #178 (Div. 2) B. Shaass and Bookshelf —— DP

    题目链接:http://codeforces.com/contest/294/problem/B B. Shaass and Bookshelf time limit per test 1 secon ...

  5. 如何把wecenter的推荐的问题模块单独调取出来?

    查阅文档: http://wenda.wecenter.com/question/1893 http://www.zhidiu.com/article/1012 http://wenda.wecent ...

  6. python学习笔记:第二天(运算符)

    Python3 运算符 注:以下部分示例源自于http://www.runoob.com/ 1.算术运算符 假设变量a为10,变量b为20: 运算符 描述 实例 + 加 - 两个对象相加 a + b ...

  7. BZOJ_3729_Gty的游戏_博弈论+splay+dfs序

    BZOJ_3729_Gty的游戏_博弈论+splay+dfs序 Description 某一天gty在与他的妹子玩游戏. 妹子提出一个游戏,给定一棵有根树,每个节点有一些石子,每次可以将不多于L的石子 ...

  8. SNE降维与可视化

    from sklearn import datasets digits = datasets.load_digits(n_class=5) X = digits.data y = digits.tar ...

  9. 推荐 BI Work

    推荐阅读 BI Work 的文章,作为学习用 http://www.cnblogs.com/biwork

  10. 爬虫库之BeautifulSoup学习(一)

    Beautiful Soup的简介 简单来说,Beautiful Soup是python的一个库,最主要的功能是从网页抓取数据. 官方解释如下: Beautiful Soup提供一些简单的.pytho ...