推荐学习书目
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 · 3689 views
    This topic created in 3575 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
        1
    loveersoldier  
       Sep 5, 2016
    record['example'] += 1
    NaVient
        2
    NaVient  
       Sep 5, 2016
    record['example']就是对应的 value 啊
    beviniy
        3
    beviniy  
       Sep 6, 2016
    from itertools import Counter
    TKKONE
        4
    TKKONE  
    PRO
       Sep 6, 2016
    突然觉得很囧
    wind3110991
        5
    wind3110991  
       Sep 12, 2016
    record = {'example' : 0}
    for i in range(0,10):
       record['example'] = record['example'] + 1

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