推荐学习书目
› 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
Newyorkcity
V2EX  ›  Python

python 如何实现 Key 对应的 value 不断加一?

  •  
  •   Newyorkcity · Sep 5, 2016 · 4050 views
    This topic created in 3725 days ago, the information mentioned may be changed or developed.

    record = {'example' : 0}
    for i in range(0,10):
       record['example'] = record['example']所对应的 value+1

    关键问题在于「 record['example']所对应的 value 」该怎么写?

    6 replies  •  2016-09-17 02:56:58 +08:00
    loveersoldier
    loveersoldier
    Sep 5, 2016
    1
    record['example'] += 1
    NaVient
    NaVient
    Sep 5, 2016
    2
    record['example']就是对应的 value 啊
    beviniy
    beviniy
    Sep 6, 2016
    3
    from itertools import Counter
    TKKONE
    TKKONE
    PRO
    Sep 6, 2016
    4
    突然觉得很囧
    wind3110991
    wind3110991
    Sep 12, 2016
    5
    record = {'example' : 0}
    for i in range(0,10):
       record['example'] = record['example'] + 1

    print record['example']
    romanticbao
    romanticbao
    Sep 17, 2016
    6
    record = {}
    DEFAULT_VALUE = 0
    for item in data_list:
    record[item] = record.get(item, DEFAULT_VALUE) + 1
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4782 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 01:59 · PVG 09:59 · LAX 17:59 · JFK 20:59
    ♥ Do have faith in what you're doing.