zoukankan      html  css  js  c++  java
  • PythonStudy——集合 Set

    # 空集合:不能用{},因为用来标示空字典

    s = set()
    print(s, type(s))

    # 概念:
    # 1.set为可变类型 - 可增可删
    # 2.set为去重存储 - set中不能存放重复数据
    # 3.set为无序存储 - 不能索引取值
    # 4.set为单列容器 - 没有取值的key
    # 总结:set不能取值

    # 增

    s.add('1')
    s.add('2')
    s.add('1')
    print(s)
    s.update({'2', '3'})
    print(s)

    # 删

    res = s.pop()
    print(res)
    s.remove('1')
    print(s)
    s.clear()
    print(s)

    # set运算
    # 交集:两个都有 &

    py = {'a', 'b', 'c', 'egon'}
    lx = {'x', 'y', 'z', 'egon'}
    print(py & lx)
    print(py.intersection(lx))

    # 合集:两个的合体 |

    print(py | lx)
    print(py.union(lx))

    # 对称交集:抛出共有的办法的合体 ^

    print(py ^ lx)
    print(py.symmetric_difference(lx))

    # 差集:独有的

    print(py - lx)
    print(py.difference(lx))

    # 比较:前提一定是包含关系

    s1 = {'1', '2'}
    s2 = {'2'}
    print(s1 < s2)

  • 相关阅读:
    HDU2201
    HDU2202 凸包
    HDU 4353 几何
    POJ2031 prim
    HDU1392 凸包
    HDU1689 BFS+最小奇数环
    设计模式 [转]
    Mining Massive Data Sets PPT
    C++编程命名规范 [转]
    static_cast与dynamic_cast转换 [转]
  • 原文地址:https://www.cnblogs.com/tingguoguoyo/p/10732596.html
Copyright © 2011-2022 走看看