zoukankan      html  css  js  c++  java
  • python-第01章07-1章节-python集合及其运用

    1.列表,元组的操作

    列表是我们会经常用到的数据类型之一,通过列表可以对数据实现最方便的存储和修改等操作

    2.定义的列表,进行关系测试

    list_1 = [1,4,5,7,8,8,9]
    list_1 = set(list_1)
    print("_________________________")
    list_2 = set([2,2,6,0,66,22,8,4,1])
    print(list_1,list_2)
    print("_________________________")
    #取两个数的交集
    print (list_1.intersection(list_2))
    print("_________________________")
    #取两个数的并集
    print(list_1.union(list_2))
    print("_________________________")
    #取两个数的差集
    print(list_1.difference(list_2))
    print(list_2.difference(list_1))
    print("_________________________")
    #判断两个列表是否为子集,父集
    print(list_1.issubset(list_2))
    print(list_2.issuperset(list_1))
    print("_________________________")
    #判断反向差集,两个中互相没有的,放在一起。
    print(list_1.symmetric_difference(list_2))

    结果:

    {1, 4, 5, 7, 8, 9} {0, 1, 2, 66, 4, 6, 8, 22}
    
    {8, 1, 4}
    _________________________
    {0, 1, 2, 66, 4, 5, 6, 7, 8, 9, 22}
    _________________________
    {9, 5, 7}
    {0, 2, 66, 6, 22}
    _________________________
    False
    False
    _________________________
    {0, 2, 66, 5, 6, 7, 9, 22}
    _________________________
    False
  • 相关阅读:
    新的
    曾经写过得太监小说3《缱绻修真界》
    Python的from和import用法
    python几个有意思的小技巧
    leetcode 最长回文串
    leetcode-快速排序C++自写
    leetcode 面试题 01.06. 字符串压缩
    leeetcode 剑指 Offer 29. 顺时针打印矩阵
    leetcode 70. 爬楼梯 续
    leetcode 1143. 最长公共子序列-华为
  • 原文地址:https://www.cnblogs.com/hanjiali/p/11573460.html
Copyright © 2011-2022 走看看