###列表相关的函数
增
lst=["adc"]
lst.append("xyz")
lst.insert(0,"李")
lst.insert(2,"凡")
print(lst)
"""要求:数据的类型是可迭代性数据"""
strvar = "1234"
lst.extend(strvar)
print(lst)
删
lst = ["晏国彰","毛洪磊","刘子涛","刘聪","牧树人"]
res = lst.pop()
print(res)
print(lst)
lst = ["晏国彰","毛洪磊","刘子涛","刘聪","牧树人","刘子涛","刘子涛"]
lst.remove("刘子涛")
print(lst)
lst = ["晏国彰","毛洪磊","刘子涛","刘聪","牧树人","刘子涛","刘子涛"]
lst.clear()
print(lst)
改查
lst = ["晏国彰","毛洪磊","刘子涛","刘聪","牧树人","刘子涛","刘子涛"]
'''列表.index(值[,start][,end]) # [] 表达参数可选项 找不到报错'''
res = lst.index("刘子涛")
res = lst.index("刘子涛",3)
print(res)
res = lst.count("刘子涛")
print(res)
"""
# 区别:字符串里面的count 可以划定范围,列表里面的count不行
strvar = "abcadaaaa"
print(strvar.count("a",1))
"""
lst = [44,99,1,10,3,-5,-90]
lst.sort()
lst.sort(reverse=True)
print(lst)
"""一位一位进行比较,在第一位相同的情况下,比较第二位,以此类推"""
lst = ["oneal","kobe","james","jordan","macdi"]
lst.sort()
print( lst )
lst = ["王文","刘德华","郭富城","张学友"]
lst.sort()
print(lst)
lst = ["王文","刘德华","郭富城","张学友"]
lst.reverse()
print(lst)
"""
a = 15
b = a
a = 16
print(b)
lst1 = [1,2,3]
lst2 = lst1
lst1.append(4)
print(lst2)
"""
import copy
lst1 = [1,2,3]
lst2 = copy.copy(lst1)
lst1.append(4)
print(lst1)
print(lst2)
lst1 = [1,2,3,4]
lst3 = lst1.copy()
lst1.insert(0,0)
print(lst1)
print(lst3)
"""
lst1 = [1,2,3,[4,5,6]]
lst2 = copy.copy(lst1)
lst1[-1].append(7)
lst1.append(100)
print(lst1)
print(lst2)
"""
lst1 = [1,2,3,[4,5,6]]
lst2 = copy.deepcopy(lst1)
print(lst2)
print(lst1)
print(id(lst2[-1]))
print(id(lst1[-1]))
print(id(lst1[0]))
print(id(lst2[0]))
lst2[0] = 1111
print(id(lst1[0]))
print(id(lst2[0]))
"""
# 总结:
(1)浅拷贝只拷贝一级容器中的所有数据
(2)深拷贝拷贝所有层级的所有元素
浅拷贝速度比深拷贝速度快
深拷贝在执行时: 如果是不可变数据,地址会暂时的指向原来数据,
如果是可变数据,直接开辟新空间
不可变数据: Number str tuple
可变数据 : list set dict
"""
dic = {}
dic["ww"] = "一表人才,除了帅气的皮囊之外,一无所有"
dic['ywz'] = "渣男"
dic["hxl"] = "抠脚老汉"
print(dic)
lst = ["ww","ywz","hxl"]
dic = {}.fromkeys(lst,None)
print(dic)
"""
dic = {}.fromkeys(lst,[])
print(dic)
dic["ww"].append(1)
print(dic)
dic["ww"] = []
dic['ywz'] =[]
dic["hxl"] =[]
"""
dic = {"top":"花木兰" , "middle":"甄姬" , "bottom":"孙尚香" , "jungle" : "钟馗" , "support":"蔡文姬" }
res = dic.pop("top")
res = dic.pop("middle","没有这个键")
print(res , dic,"<=======>")
res = dic.popitem()
print(res, dic)
dic.clear()
print(dic)
dic = {'ww': '一表人才,除了帅气的皮囊之外,一无所有', 'ywz': '渣男', 'hxl': '抠脚老汉'}
dic_new = {"ywz":"暖男","hxl":"扣手","ly":"小美女,单纯,可爱,活泼,灵巧...."}
dic.update(dic_new)
print(dic)
dic.update(kxq="聪明,活泼,可爱,灵巧,惹人喜欢",ccg="乐观,大方,可爱,灵巧")
print(dic)
dic = {'ww': '一表人才,除了帅气的皮囊之外,一无所有', 'ywz': '暖男', 'hxl': '扣手'}
res = dic.get("ww")
res = dic.get("zbcdefg")
res = dic.get("zbcdefg","没有这个键")
print(res)
dic = {'ww': '一表人才,除了帅气的皮囊之外,一无所有', 'ywz': '暖男', 'hxl': '扣手'}
res = dic.keys()
print(res)
res = dic.values()
print(res)
res = dic.items()
print(res)
set1 = {"jacklove","theshy","rookie","xboyww"}
set2 = {"倪萍","张国荣","赵本山","刘能","赵四","xboyww"}
res = set1.intersection(set2)
print(res)
res = set1 & set2
print(res)
res = set1.difference(set2)
print(res)
res = set1 - set2
print(res)
res = set1.union(set2)
print(res)
res = set1 | set2
print(res)
res = set1.symmetric_difference(set2)
print(res)
res = set1 ^ set2
print(res)
set1 = {"周杰伦","王力宏","罗志祥","潘玮柏"}
set2 = {"周杰伦","王力宏"}
res = set1.issubset(set2)
print(res)
res = set1 < set2
print(res)
res = set1.issuperset(set2)
print(res)
res = set1 > set2
print(res)
res = set1.isdisjoint(set2)
print(res)
setvar = {"神秘男孩","金角大王"}
setvar.add("银角大王")
print(setvar)
strvar = ("刘子豪","刘鑫")
setvar.update(strvar)
print(setvar)
res = setvar.pop()
print(res , setvar)
setvar.discard("神秘男孩")
setvar.discard("神秘男孩1234324")
print(setvar)
"""冰冻集合一旦创建,不能在进行任何修改,只能做交叉并补操作"""
lst1 = ["王闻",18,"男性","爱好:跑步"]
fz1 = frozenset(lst1)
lst2 = ("王闻","地址:包头","买一辆特斯拉9.9包邮")
fz2 = frozenset(lst2)
print(fz1 , type(fz1))
print(fz2 , type(fz2))
print( fz1 & fz2 )
print( fz1 - fz2 )