zoukankan      html  css  js  c++  java
  • 集合

    #!/usr/bin/env python
    list_1 = [1,4,5,7,3,6,7,9]
    list_1 = set (list_1) #集合,没有重复数,无序
    list_2 = set ([2,6,0,66,22,8,4])
    print(list_1,list_2)
    print(list_1.intersection(list_2))#交集
    print(list_1 & list_2)#交集
    print(list_1.union(list_2) )#并集
    print(list_1 | list_2)#并集
    print(list_1.difference(list_2))#差集
    print(list_1 - list_2)#差集
    print(list_1.issubset(list_2))#是否子集
    print(list_1.issuperset(list_2))#是否父集
    print(list_1.symmetric_difference(list_2))#对称差集,去掉并集后剩余的并集
    print(list_1 ^ list_2)#对称差集,去掉并集后剩余的并集
    print("-------------")
    print(list_2.isdisjoint(list_1))#是否无交集
    list_1.add(999)#添加
    list_1.update([888,777])#添加
    print(list_1)
    print(len(list_1))#长度
    '777' in list_1#列表,字典,集合,字符串;是否在。。。里
    print(list_1.pop())#删除1个,无序
    list_1.discard("777")#删除指定值,值可以不存在
    list_1.remove(888) #删除指定值,值必须存在
    #copy,pop,remove,
    print(list_1)



    {1, 3, 4, 5, 6, 7, 9} {0, 2, 66, 4, 6, 8, 22}
    {4, 6}
    {4, 6}
    {0, 1, 2, 3, 4, 5, 6, 7, 66, 9, 8, 22}
    {0, 1, 2, 3, 4, 5, 6, 7, 66, 9, 8, 22}
    {1, 3, 5, 7, 9}
    {1, 3, 5, 7, 9}
    False
    False
    {0, 1, 2, 66, 3, 5, 8, 7, 9, 22}
    {0, 1, 2, 66, 3, 5, 8, 7, 9, 22}
    -------------
    False
    {1, 3, 4, 5, 6, 7, 999, 9, 777, 888}
    10
    1
    {3, 4, 5, 6, 7, 999, 9, 777}

  • 相关阅读:
    工作流资源模式
    工作流资源模式
    工作流资源模式
    工作流资源模式
    工作流模式-工作流资源模式43种
    pmbok中文第六版官方在线版(班主任推荐)
    PMP项目管理知识体系指南(PMBOK指南)第六版,无水印、无密码、带目录、高清
    五、行为型模式
    四、结构型模式
    一、UML
  • 原文地址:https://www.cnblogs.com/rongye/p/9911420.html
Copyright © 2011-2022 走看看