V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2013-06-08 16:13:46 +08:00 · 5127 次点击
    这是一个创建于 3946 天前的主题,其中的信息可能已经有所发展或是发生改变。
    看了点算法的介绍,但是没有代码实现,不得要领。
    求V2EX高手赐教。。
    4 条回复    1970-01-01 08:00:00 +08:00
    kingxsp
        1
    kingxsp  
       2013-06-10 21:35:37 +08:00
    推荐pybloomfiltermmap库。
    binux
        2
    binux  
       2013-06-10 21:53:18 +08:00
    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
       2013-06-10 23:18:37 +08:00
    @binux 这段代码运行报错,能否show一个gist,最好有一个小demo,非常感谢。
    xavierskip
        4
    xavierskip  
       2013-06-11 00:25:12 +08:00
    过滤重复url

    这样行不行?

    list( set( urls ) )
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1188 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 18:15 · PVG 02:15 · LAX 11:15 · JFK 14:15
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.