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:




  • 相关阅读:
    串口调适
    取出不重复的6个数
    个人Windows 10必备软件以及浏览器必装插件等
    合肥工业大学宣城校区2018年-2019年第一学期(大三上学期)物联网工程专业资料汇总(含课件、个人实验报告、实验代码、课设报告等)
    合肥工业大学宣城校区2019年-2020年第二(大三下)学期物联网工程专业资料汇总(含课件、个人实验报告、实验代码、课设报告等)
    合肥工业大学宣城校区2020年-2021年第一(大四上)学期物联网工程专业资料汇总(含课件、个人实验报告、实验代码、课设报告等)
    软件工程-单元测试-计算机测试-复习札记
    8086汇编计算分段函数值
    C语言是开源的吗?C++是开源的吗?C语言、C++是两个开源的标准,而不是开源软件或其它
    合肥工业大学编译原理实验LR(1)文法分析完整Scala实现代码(Java封装GUI)与测试数据
  • 原文地址:https://www.cnblogs.com/baotouzhangce/p/6155161.html
Copyright © 2011-2022 走看看