摘要: • dict查找的性能远远大于list • 在list中随着list数据的增大,查找时间会增大 • 在dict中查找元素不会随着dict的增大而增大 dict的存储结构 • dict的key或者set的值,都必须是可以hash的 • 不可变对象,都是可以hash的,str、frozenset、tup 阅读全文
posted @ 2019-07-26 18:00 _simpleSmile 阅读(225) 评论(0) 推荐(0) 编辑
摘要: 1 #!/user/bin/env python 2 # -*- coding:utf-8 -*- 3 # set集合 frozenset不可变集合, 无序、不重复 4 # set()函数接收一个可迭代对象 5 # s = set('abcdefa') 6 s = {'a', 'b'} 7 s.add('c') 8 print(s) 9 10 # frozenset不可变集合... 阅读全文
posted @ 2019-07-26 15:44 _simpleSmile 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 1 #!/user/bin/env python 2 # -*- coding:utf-8 -*- 3 # 不建议继承list和dict 4 from collections import UserDict 5 from collections import defaultdict 6 7 8 class MyDict1(dict): 9 def __setitem... 阅读全文
posted @ 2019-07-26 15:24 _simpleSmile 阅读(183) 评论(0) 推荐(0) 编辑
摘要: 1 #!/user/bin/env python 2 # -*- coding:utf-8 -*- 3 import copy 4 a = {'zy': 123} 5 6 # clear 7 a.clear() 8 print(a) 9 10 # copy,返回浅拷贝 11 b = {'zy': {'school': 'hx'}} 12 new_dict = b.copy(... 阅读全文
posted @ 2019-07-26 15:12 _simpleSmile 阅读(208) 评论(0) 推荐(0) 编辑
摘要: 1 #!/user/bin/env python 2 # -*- coding:utf-8 -*- 3 # dict属于mapping类型 4 from collections.abc import Mapping, MutableMapping 5 a = {} 6 print(isinstance(a, MutableMapping)) 阅读全文
posted @ 2019-07-26 14:50 _simpleSmile 阅读(175) 评论(0) 推荐(0) 编辑
摘要: • 列表推导式 • 生成器表达式 • 字典推导式 阅读全文
posted @ 2019-07-26 01:15 _simpleSmile 阅读(322) 评论(0) 推荐(0) 编辑
摘要: 1 #!/user/bin/env python 2 # -*- coding:utf-8 -*- 3 4 # 用来处理已排序的序列,用来维持已排序的序列,升序 5 # 二分查找 6 import bisect 7 8 9 inter_list = [] 10 bisect.insort(inter_list, 3) 11 bisect.insort(inter_list... 阅读全文
posted @ 2019-07-26 00:36 _simpleSmile 阅读(182) 评论(1) 推荐(0) 编辑
摘要: 上述是切片常用的操作,下面代码将实现一个可切片的对象 阅读全文
posted @ 2019-07-26 00:23 _simpleSmile 阅读(244) 评论(0) 推荐(0) 编辑