集合操作相關
阿新 • • 發佈:2018-09-01
重復 hang update pre date ken fault () let
#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))
集合操作相關