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

如何提高python中字典类型中的数据之间比较的效率

  •  
  •   gavinlw · Nov 9, 2012 · 5118 views
    This topic created in 5072 days ago, the information mentioned may be changed or developed.
    有这样一个场景:
    一个字典中有1000个键值对,每个值是包含200个以内词语的列表
    如何快速计算出所有值(也就是说所有词语)在字典的某条记录中是否出现,以及出现次数~
    也就是统计记录中包含该词的条目数。
    2 replies  •  1970-01-01 08:00:00 +08:00
    phuslu
        1
    phuslu  
       Nov 9, 2012
    collections.defaultdict(collections.Counter)

    python 2.7
    013231
        2
    013231  
       Nov 9, 2012
    這種問題用reduce解決最簡單了:
    http://gist.github.com/4046085
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1012 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 18:33 · PVG 02:33 · LAX 11:33 · JFK 14:33
    ♥ Do have faith in what you're doing.