V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · Jul 27, 2017 · 2678 views
    This topic created in 3197 days ago, the information mentioned may be changed or developed.
    Supplement 1  ·  Jul 27, 2017
    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 replies    2017-07-27 17:09:21 +08:00
    xylsmmmmmmmm3
        1
    xylsmmmmmmmm3  
    OP
       Jul 27, 2017
    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
       Jul 27, 2017
    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:
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3906 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 10:28 · PVG 18:28 · LAX 03:28 · JFK 06:28
    ♥ Do have faith in what you're doing.