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

用 python 写了个判断字符串相似程度的函数

  •  
  •   luosch · Jan 1, 2016 · 4471 views
    This topic created in 3822 days ago, the information mentioned may be changed or developed.

    在某个项目中遇到判断字符串相似程度的需求, google 了一下,原来python标准库里面没有这样的函数,反而是 PHP 里面有一个similar_text()函数,果然PHP 是世界上最好的编程语言,于是查看 PHP 源码后把这个函数移植到了 python

    安装

    pip install similar_text
    

    使用

    >>> from similar_text import similar_text
    >>> similar_text('swift', 'taylor swift')
    58.8235294117647
    >>> similar_text('jzm', 'jiangzemin')
    46.15384615384615
    

    项目地址: https://github.com/luosch/similar_text

    第一次写 pypi 的库,有什么做错的求轻喷

    9 replies    2016-01-01 21:31:56 +08:00
    aheadlead
        1
    aheadlead  
       Jan 1, 2016
    编辑距离!
    以前做 OI 的时候入门的 DP 题~
    luosch
        2
    luosch  
    OP
       Jan 1, 2016
    @aheadlead 编辑距离得到的匹配度不是很准确,所以准备弃用了
    imn1
        3
    imn1  
       Jan 1, 2016
    又是重复造轮子?
    Kisesy
        4
    Kisesy  
       Jan 1, 2016   ❤️ 4
    其实是有的。。。。
    import difflib
    print(difflib.SequenceMatcher(None, 'jzm', 'jiangzemin').quick_ratio())
    virusdefender
        5
    virusdefender  
       Jan 1, 2016
    icedx
        6
    icedx  
       Jan 1, 2016
    参考 simhash
    trdcaz
        7
    trdcaz  
       Jan 1, 2016 via iPhone
    @Kisesy 正解
    DeanThompson
        8
    DeanThompson  
       Jan 1, 2016
    luosch
        9
    luosch  
    OP
       Jan 1, 2016 via iPhone
    @DeanThompson 已经被打击惨了😂
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2713 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 44ms · UTC 13:09 · PVG 21:09 · LAX 06:09 · JFK 09:09
    ♥ Do have faith in what you're doing.