• 集合的方法


     1 #set是可变的数据类型,里面的元素是不可变的,无序,不重复
     2 # set1 = {1, 'str', False, (1, 2, 3), 1, 1}
     3 # print(set1)
     4 
     5 #增add
     6 # set1 = {'chuan', 'huang', 'lin', 'li'}
     7 # set1.add('liu')
     8 # print(set1)
     9 #
    10 # #update迭代元素的更新
    11 # set1.update('abc')
    12 # print(set1)
    13 
    14 
    15 #
    16 # set1 = {'chuan', 'huang', 'lin', 'li'}
    17 # print(set1.pop())
    18 # print(set1)
    19 #
    20 # set1.remove('huang')        #按元素去删
    21 # print(set1)
    22 #
    23 # set1.clear()                #清空
    24 # del set1                    #删除
    25 
    26 
    27 #
    28 # set1 = {'chuan', 'huang', 'lin', 'li'}
    29 # for i in set1:
    30 #     print(i)
    31 
    32 #集合的并集
    33 # set1 = {1,2,3,4}
    34 # set2 = {3,4,5,6}
    35 # set3 = set1 & set2
    36 # print(set3)           #{3, 4}
    37 # print(set1.intersection(set2))    #{3, 4}
    38 
    39 
    40 #集合的交集
    41 # set1 = {1,2,3,4}
    42 # set2 = {3,4,5,6}
    43 # set3 = set1 | set2
    44 # print(set3)           #{1, 2, 3, 4, 5, 6}
    45 # print(set1.union(set2))    #{1, 2, 3, 4, 5, 6}
    46 
    47 #反交集
    48 # set1 = {1,2,3,4}
    49 # set2 = {3,4,5,6}
    50 # print(set1 ^ set2)           #{1, 2, 5, 6}
    51 # print(set1.symmetric_difference(set2))       #{1, 2, 5, 6}
    52 
    53 #差集,set1和set2去除相同部分而剩下的元素
    54 # set1 = {1,2,3,4}
    55 # set2 = {3,4,5,6}
    56 # print(set1 - set2)     #{1,2}
    57 # print(set1.difference(set2))      #{1,2}
    58 
    59 #超集和子集
    60 # set1 = {1,2,3,4}
    61 # set2 = {1,2,3,4,5,6}
    62 # print(set1 < set2)
    63 # print(set1.issubset(set2))
    64 # print(set2 > set1)
    65 # print(set2.issuperset(set1))
    66 
    67 #去除相同的元素
    68 # li = [1,55,6,2,3,4,6,6,3]
    69 # set1 = set(li)
    70 # print(set1)
    71 # li = list(set1)
    72 # print(li)
    73 
    74 
    75 #转换为不可变数据类型
    76 # set2 = frozenset('abcd')
    77 # print(set2, type(set2))
  • 相关阅读:
    练习:给Keras ResNet50源码加上正则化参数, 修改激活函数为Elu
    凸集,凸函数,凸优化问题。
    Keras用动态数据生成器(DataGenerator)和fitgenerator动态训练模型
    Lagrangian 对偶 和 Slater 条件
    凸集分离定理
    Python 中的 sorted 和 sort的区别
    工作反思
    jemalloc
    libcoap
    dropbear
  • 原文地址:https://www.cnblogs.com/hhsh/p/9503146.html
Copyright © 2020-2023  润新知