zoukankan      html  css  js  c++  java
  • python对ip地址排序、对列表进行去重

    一:使用python对ip地址排序所用代码
    示例一:
        import socket
        iplist = ['10.5.11.1','192.168.1.33','10.5.2.4','10.5.1.3','10.5.11.13','10.5.11.12','10.5.1.1','10.5.1.2','10.5.1.11','10.5.1.13']
        print(sorted(iplist,key=socket.inet_aton))
        for i in sorted(iplist,key=socket.inet_aton):
            print(i)
    示例二:
        iplist = ['192.168.1.33','10.5.2.4','10.5.1.3','202.98.96.68','133.120.1.1','192.168.1.22']
        print(sorted(iplist,key = lambda x: ( int(x.split('.')[0]), int(x.split('.')[1]), int(x.split('.')[2]) )))
    
        ip_l = sorted(iplist,key = lambda x: ( int(x.split('.')[0]), int(x.split('.')[1]), int(x.split('.')[2]) ))
        for i in ip_l:
            print(i)

     二:使用字典函数对列表进行去重

     示例:

        a = [1,2,3,2,2,4,5,2,34,4,562,23,4,4,2,24,2,4,2,24,2,]
    
        b = {}
        b = b.fromkeys(a)
    
        print(list(b.keys()))

       结果:

        [1, 2, 3, 4, 5, 34, 562, 23, 24]



  • 相关阅读:
    微信扫码
    vue h5公众号支付
    vue h5支付宝支付
    vue PDF预览
    vue 中AES加密
    vue 动态路由配置
    移动端调试工具
    Ajax工作原理
    yahoo军规
    Flex 布局教程
  • 原文地址:https://www.cnblogs.com/hsggj/p/8376924.html
Copyright © 2011-2022 走看看