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

如何用布隆过滤器过滤重复url,求Python代码实现。

  •  
  •   kenneth · Jun 8, 2013 · 5918 views
    This topic created in 4883 days ago, the information mentioned may be changed or developed.
    看了点算法的介绍,但是没有代码实现,不得要领。
    求V2EX高手赐教。。
    4 replies  •  1970-01-01 08:00:00 +08:00
    kingxsp
        1
    kingxsp  
       Jun 10, 2013
    推荐pybloomfiltermmap库。
    binux
        2
    binux  
       Jun 10, 2013
    import hashlib

    hash = hashlib.md5
    bloom = 0

    def check(str):
    global bloom
    str_hash = hash(str)
    if bloom & int(str_hash.hexdigest(), 16) == 256 ** str_hash.digest_size:
    return True
    bloom |= int(str_hash.hexdigest(), 16)
    return False
    kenneth
        3
    kenneth  
    OP
       Jun 10, 2013
    @binux 这段代码运行报错,能否show一个gist,最好有一个小demo,非常感谢。
    C0VN
        4
    C0VN  
       Jun 11, 2013
    过滤重复url

    这样行不行?

    list( set( urls ) )
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   961 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 21:47 · PVG 05:47 · LAX 14:47 · JFK 17:47
    ♥ Do have faith in what you're doing.