zoukankan      html  css  js  c++  java
  • python之集合(set)

    一、集合的特点:
      1、访问速度快
      2、天生解决了重复问题
    二、集合的定义方法:
      a=set()
      b=set(['a','b','c'])
    三、集合中的方法:
    def add(self, *args, **kwargs): # real signature unknown
    """
    Add an element to a set.

    This has no effect if the element is already present.
      在集合中增加元素
    """
    pass
    eg:


    def clear(self, *args, **kwargs): # real signature unknown
    """
        Remove all elements from this set.
        清空集合
       """
    pass
    eg:

    def copy(self, *args, **kwargs): # real signature unknown
    """
        Return a shallow copy of a set.
        集合的浅拷贝
      """
    pass

    def difference(self, *args, **kwargs): # real signature unknown
    """
    Return the difference of two or more sets as a new set.

    (i.e. all elements that are in this set but not the others.)
      求两个集合的不同(差集),生成一个新的集合
    """
    pass
    eg:


    def difference_update(self, *args, **kwargs): # real signature unknown
    """
        Remove all elements of another set from this set.
        求两个集合的不同(差集),改变原来的集合
       """
    pass
    eg:

    def discard(self, *args, **kwargs): # real signature unknown
    """
    Remove an element from a set if it is a member.

    If the element is not a member, do nothing.
      移除集合中的一个指定元素,如果这个元素不存在,则不变
    """
    pass


    def intersection(self, *args, **kwargs): # real signature unknown
    """
    Return the intersection of two sets as a new set.

    (i.e. all elements that are in both sets.)
      求两个集合的交集,生成一个新的集合
    """
    pass
    eg:


    def intersection_update(self, *args, **kwargs): # real signature unknown
    """
        Update a set with the intersection of itself and another.
        求两个集合的交集,并改变原集合
       """
    pass
    eg:


    def isdisjoint(self, *args, **kwargs): # real signature unknown
    """
        Return True if two sets have a null intersection.
        判断两个集合是否没有交集,如果是返回True,如果不是返回False
      """
    pass
    eg:



    def issubset(self, *args, **kwargs): # real signature unknown
    """
        Report whether another set contains this set.
        判断一个集合是否是另一个集合的子集
      """
    pass
    eg:



    def issuperset(self, *args, **kwargs): # real signature unknown
    """
        Report whether this set contains another set.
        判断一个集合是否包含另一个集合
       """
    pass
    eg:



    def pop(self, *args, **kwargs): # real signature unknown
    """
    Remove and return an arbitrary set element.
    Raises KeyError if the set is empty.
      弹出集合中的元素
    """
    pass
    eg:


    def remove(self, *args, **kwargs): # real signature unknown
    """
    Remove an element from a set; it must be a member.

    If the element is not a member, raise a KeyError.
      移除集合中的元素
    """
    pass
    eg:



    def symmetric_difference(self, *args, **kwargs): # real signature unknown
    """
    Return the symmetric difference of two sets as a new set.

    (i.e. all elements that are in exactly one of the sets.)
      把两个集合中的不同元素放到一个新的集合中
    """
    pass
    eg:



    def symmetric_difference_update(self, *args, **kwargs): # real signature unknown
    """
        Update a set with the symmetric difference of itself and another.
        两个集合不相同的元素,并改变原集合
      """
    pass
    eg:



    def union(self, *args, **kwargs): # real signature unknown
    """
    Return the union of sets as a new set.

    (i.e. all elements that are in either set.)
      求两个集合的并集,并生成一个新的集合
    """
    pass
    eg:


    def update(self, *args, **kwargs): # real signature unknown
    """
        Update a set with the union of itself and others.
        改变原集合
      """
    pass
    eg:




  • 相关阅读:
    React路由基本的使用(一)
    Codeforces Round #627 (Div. 3) C
    Codeforces Round #627 (Div. 3) B
    Codeforces Round #627 (Div. 3) A
    hdu2049 不容易系列之(4)——考新郎(组合,错排)
    Codeforces Round #626 (Div. 2) E. Instant Noodles(二分图,最大公因数)
    Codeforces Round #626 (Div. 2) D. Present(位运算)
    逆元的计算方法
    Educational Codeforces Round 83 D. Count the Arrays(组合,逆元,快速幂)
    hdu4460 Friend Chains(记忆化广度优先搜索)
  • 原文地址:https://www.cnblogs.com/baotouzhangce/p/6155161.html
Copyright © 2011-2022 走看看