V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
xylsmmmmmmmm3
V2EX  ›  Python

双重循环+遍历中修改字典//RuntimeError: dictionary changed size during iteration

  •  
  •   xylsmmmmmmmm3 · 2017-07-27 17:03:22 +08:00 · 2250 次点击
    这是一个创建于 2458 天前的主题,其中的信息可能已经有所发展或是发生改变。
    第 1 条附言  ·  2017-07-27 17:56:27 +08:00
    shuzi = {'1': {'end': 3247341040L, 'star': 3247341040L}, 2: {'end': 1033039063, 'star': 1033039056},3:{'end':111,'star':2222222222222}}
    for key1 in shuzi.keys():
    if not shuzi.has_key(key1):
    break
    for key2 in shuzi.keys():
    3 条回复    2017-07-27 17:09:21 +08:00
    xylsmmmmmmmm3
        1
    xylsmmmmmmmm3  
    OP
       2017-07-27 17:04:32 +08:00
    shuzi = {'1': {'end': 3247341040L, 'star': 3247341040L}, 2: {'end': 1033039063, 'star': 1033039056},3:{'end':111,'star':2222222222222}}
    for key1 in shuzi.keys():
    print key1
    if not shuzi.has_key(key1):
    break
    for key2 in shuzi:

    """
    有没有更好得解决方法?
    xylsmmmmmmmm3
        2
    xylsmmmmmmmm3  
    OP
       2017-07-27 17:05:16 +08:00
    shuzi = {'1': {'end': 3247341040L, 'star': 3247341040L}, 2: {'end': 1033039063, 'star': 1033039056},3:{'end':111,'star':2222222222222}}
    for key1 in shuzi.keys():
    if not shuzi.has_key(key1):
    break
    for key2 in shuzi:
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   934 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 22:21 · PVG 06:21 · LAX 15:21 · JFK 18:21
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.