zoukankan      html  css  js  c++  java
  • 集合操作相关

    #set -------> set
    # str

    # lis = [11,2,3,4]
    #
    # for i in range(len(lis)):
    # print(i)
    #
    # del lis[i]
    # print(lis)
    # # print(lis)

    # lis = [11,22,33,44]
    #
    # for i in range(len(lis)):
    # lis.pop()
    #
    # print(lis)

    # l1 = [11,22]
    # l2 = l1
    # l3 = l2
    # l3.append("a")
    # print(l1)
    # print(l2)
    # print(l3)

    dic = {"k1":"v1", "k2":"v2", "a3":"v3"}
    dic1 = {}
    # for i in dic:
    # if "k" not in i:
    # dic1.setdefault(i, dic[i])
    #
    # dic = dic1
    # print(dic)
    #
    # l = []
    #
    # for i in dic:
    # if "k" in i:
    # l.append(i)
    # for i in l:
    # if i in dic:
    # del dic[i]
    #
    # print(dic)

    #0 '' [] () {} set() ----> bool False

    '''
    集合:可变的数据类型,它里面的元素必须是不可变的数据类型, 无序, 不重复
    {}

    '''
    # set1 = set({1,2,3})
    # set2 = {1,2,3,}
    # print(set2)
    # # add two method add, update
    set1 = {'alex', 'wusir','ritian', 'egon'}
    # # set1.add("girl")
    # # print(set1)
    # # update
    # set1.update("abc")
    # print(set1)

    # delete two method pop, remove ,clear
    # item = set1.pop()
    #
    # print(item)
    # set1.remove("alex")
    # print(set1)

    # set1.clear()
    # print(set1)

    # del set1
    # print(set1)

    # for i in set1:
    # print(i)

    #intersection
    set1 = {'alex', 'wusir','ritian', 'egon'}
    set2 = {"jin", "ken", "alex"}
    # print(set2 & set1)
    # print(set1.intersection(set2))
    #union
    # print(set1 | set2)
    # print(set2.union(set1))
    #反交集
    # print(set1 ^ set2)
    # print(set2.symmetric_difference(set1))
    #difference
    # print(set1 - set2)
    # print(set1.difference(set2))

    set1 = {1,2,3}
    set2 = {1,2,3,4,5,6}
    # print(set1 < set2)
    # print(set1.issubset(set2))

    # print(set2 > set1)
    # print(set2.issuperset(set1))

    # li = [1,2,33,33,2,1,4,5,6,6]
    # set1 = set(li)
    # print(set1)
    # li = list(set1)
    # print(li)

    #frozenset --->unchanged
    # s = frozenset("baarry")
    #
    # print(s,type(s))
  • 相关阅读:
    《简养脑》读书笔记
    如何用86天考上研究生
    Improving your submission -- Kaggle Competitions
    Getting started with Kaggle -- Kaggle Competitions
    入门机器学习
    《世界因你不同》读书笔记
    [转载]Python 包构建教程
    [转载] Pytorch拓展进阶(二):Pytorch结合C++以及Cuda拓展
    集合不能存放重复元素
    在jupyter notebook中绘制KITTI三维散点图
  • 原文地址:https://www.cnblogs.com/jly1/p/9570287.html
Copyright © 2011-2022 走看看