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
tan9O
V2EX  ›  Python

遇到个重复 IP 合并的问题,麻烦大佬们帮忙看一下

  •  
  •   tan9O · 332 天前 · 742 次点击
    这是一个创建于 332 天前的主题,其中的信息可能已经有所发展或是发生改变。
    # 有这样的 IP 范围集合,集合元素的 IP 格式有单 IP 也有带-的 IP 段,也有 CIDR 格式的
    data = ['1.1.1.1', '1.1.1.1-2.2.2.5', '1.1.1.3-1.1.1.6', '1.1.1.0/24', '1.1.0.0/16', '3.3.3.6', '3.3.3.1-3.3.3.10', '3.3.3.3/24']
    

    现在需要合并列表中重复部分的 IP 地址 1.1.0.0/16 这种和 1.1.1.1-2.2.2.5 合并成带-的形式

    ztmzzz
        1
    ztmzzz  
       332 天前 via iPhone
    都转换为区间的形式,然后问题就转化为多个区间,求总区间。应该有类似的算法题
    tan9O
        2
    tan9O  
    OP
       332 天前
    @ztmzzz 嗯嗯 突然想到了
    ophark
        3
    ophark  
       331 天前
    一般来说都是点分十进制转换成纯数字再按数字大小判断重合就行了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3089 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 13:47 · PVG 21:47 · LAX 06:47 · JFK 09:47
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.