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

被 min() 给坑了

  •  
  •   fcicq · Jul 10, 2011 · 6502 views
    This topic created in 5421 days ago, the information mentioned may be changed or developed.
    实际上要的是这个...
    def returnmin(d):
    return min(d,key = lambda a: d.get(a))

    测试
    min({'a':5, 'b':4, 'c':3}), 比较的是 key 而不是 value...
    4 replies    1970-01-01 08:00:00 +08:00
    bcxx
        1
    bcxx  
       Jul 10, 2011
    最害怕就是字典排序了TAT
    shellex
        2
    shellex  
       Jul 10, 2011
    当然。
    phus
        3
    phus  
       Jul 11, 2011
    min/max/list/set都假设的参数是iterable的。
    因为dict的__iter__是返回key, 所以min就比较key了。
    blackbird
        4
    blackbird  
       Jul 11, 2011
    min(d, key=d.get)
    这样写也行
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1186 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 53ms · UTC 23:32 · PVG 07:32 · LAX 16:32 · JFK 19:32
    ♥ Do have faith in what you're doing.