zoukankan      html  css  js  c++  java
  • 1、str.join() 2、fromkeys() 3、深浅拷贝 4、set()

    • 1. 补充基础数据类型的相关知识点
    • 1. str. join() 把列表变成字符串
    • 2. 列表不能再循环的时候删除. 因为索引会跟着改变
    • 3. 字典也不能直接循环删除.
    • 把要删除的内容记录在列表中. 循环列表. 删除原列表, 字典中的数据
    • 4. fromkeys() 不会对原来的字典产生影响. 产生新字典(神坑, 考试)
    • 5. set集合. 不重复, 无序.
    • 6. 想转换成什么.就用什么括起来
    • 7. 深浅拷贝
    • 1. 直接赋值. 两个变量指向同一个对象.
    • 2. 浅拷贝:只拷贝第一层内容. copy()
    • 3. 深度拷贝: 对象中的所有内容都会被拷贝一份
    • import copy
    • copy.deepcopy()
    • # # 浅拷贝 copy
    • # import copy
    • # lst = ["str1", "str2", "str3", "str4", "str5"]
    • # sourcelst = ["str1", "str2", "str3", "str4", "str5", lst]
    • # copylst = copy.copy(sourcelst)
    • # print(sourcelst)
    • # print(copylst)
    • #
    • # sourcelst.append("sourcestr")
    • # copylst.append("copystr")
    • # print(sourcelst)
    • # print(copylst)
    • #
    • # sourcelst[0] = "changeSource"
    • # print(sourcelst)
    • # print(copylst)
    • #
    • # lst.append("testAppend")
    • # print(sourcelst)
    • # print(copylst)
    • #
    • # # 深拷贝 deepcopy
    • # import copy
    • # lst = ["str1", "str2", "str3", "str4", "str5"]
    • # sourcelst = ["str1", "str2", "str3", "str4", "str5", lst]
    • # deepcopylst = copy.deepcopy(sourcelst)
    • # print(sourcelst)
    • # print(deepcopylst)
    • #
    • # sourcelst.append("sourcestr")
    • # deepcopylst.append("copystr")
    • # print(sourcelst)
    • # print(deepcopylst)
    • #
    • # sourcelst[0] = "changeSource"
    • # print(sourcelst)
    • # print(deepcopylst)
    • #
    • # lst.append("testAppend")
    • # print(sourcelst)
    • # print(deepcopylst)
    • # s = "sb".join("贱人")
    • # print(s)
    • # s = ["周杰伦", "周润发", "麻花藤", "周树人"]
    • # lis = []
    • # for i in s:
    • # if i[0] == "周":
    • # lis.append(i)
    • # for j in lis:
    • # if j in s:
    • # s.remove(j)
    • # print(s)
    • # s = "abc"
    • # s1 = s.join("非常可乐")
    • # print(s1)
    • # s = "_".join((["alex", "wuse", "taibai", "ritian"]))
    • # print(s)
    • # s = "sb".join(["王者荣耀", "LOL", "跑跑卡丁车"])
    • # print(s)
    • # list dic 在循环的时候不能删, 因为会改变索引
    • # lst = ["我不是药神", "西游记", "西红柿首富", "天龙八部"]
    • # del_lst = []
    • # for i in lst:
    • # del_lst.append(i) # 记录下来要删除的内容
    • # for j in del_lst:
    • # lst.remove(j)
    • # print(lst)
    • # lst = ["周杰伦", "周润发", "周星星", "马化腾", "周树人"]
    • # # 删除掉姓周的人的信息
    • # del_lst = []
    • # for el in lst:
    • # if el.startswith("周"):
    • # del_lst.append(el)
    • # for el in del_lst:
    • # lst.remove(el)
    • # print(lst)
    • # dic = {"a": "123", "b": "456"}
    • # for k in dic:
    • # dic.setdefault("c", "123") # 错误的
    • # a = dict.fromkeys(["jj", "jay", "taibai", "sb"]) # 静态方法
    • # print(a)
    • # dic = {"a": "123"}
    • # s = dic.fromkeys("王健林", "思聪") # 返回给你一个新字典
    • # print(s)
    • # s = set() # 空集合
    • # dic = dict()
    • # s = str()
    • # i = int()
    • # lst = list()
    • # print(i)
    • # s = {"王者荣耀", "英雄联盟", "王者荣耀", 123, True, True} # 集合中都是不一样的元素,输入以后会合并相同的元素
    • # print(s)
    • # s = {123, {1, 2, 3}} # 不合法
    • # print(s)
    • # lst = ["张强", "李强", "王磊", "刘伟", "张伟", "张伟", "刘洋", "刘洋"]
    • # s = set(lst) # 去重复
    • # print(s)
    • # 变回来
    • # lst = list(s)
    • # print(lst)
    • # 冻结了的set集合,可哈希的,不可变
    • # s = frozenset([1, 3, 6, 6, 9, 8]) # 可以去重复, 也是set集合
    • # print(s)
    • # ss = {"a", s}
    • # print(ss)
  • 相关阅读:
    Linux 3.2中回写机制的变革
    Linux字符设备与块设备的区别与比较
    分布式文件系统:原理、问题与方法
    为什么说B+-tree比B 树更适合实际应用中操作系统的文件索引和数据库索引?
    Linux IO barrier
    磁盘IO:缓存IO与直接IO
    【珍藏】高性能IO模型浅析
    souretree+上面提交代码和gerrit上面出现Cannot+merge的时候的解决方法
    vscode快速生成自定义HTML模板
    在jq里面设置样式的高度height、设置隐藏和显示的小功能
  • 原文地址:https://www.cnblogs.com/wjs521/p/9291960.html
Copyright © 2011-2022 走看看