上一页 1 ··· 5 6 7 8 9 10 11 下一页
摘要: 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) 编辑
摘要: 1 #!/user/bin/env python 2 # -*- coding:utf-8 -*- 3 4 a = [1, 2] 5 c = a + [3, 4] 6 print(c) 7 8 # += 加上一个可迭代的类型 9 # += 通过__iadd__魔法函数实现,__iadd__内部调用了extend()方法 10 a += (3, 4) 11 print(a) ... 阅读全文
posted @ 2019-07-25 17:46 _simpleSmile 阅读(708) 评论(0) 推荐(0) 编辑
摘要: 容器序列和扁平序列的区别在于,扁平序列里面的元素类型都是一样的 阅读全文
posted @ 2019-07-25 17:27 _simpleSmile 阅读(425) 评论(0) 推荐(0) 编辑
摘要: 1 #!/user/bin/env python 2 # -*- coding:utf-8 -*- 3 import contextlib 4 5 6 @contextlib.contextmanager 7 def file_open(file_name): 8 print('file_open') 9 yield 10 print('file e... 阅读全文
posted @ 2019-07-24 17:17 _simpleSmile 阅读(171) 评论(0) 推荐(0) 编辑
摘要: 1 #!/user/bin/env python 2 # -*- coding:utf-8 -*- 3 4 # 上下文管理器协议 5 6 7 class Sample: 8 def __enter__(self): 9 print('enter') 10 return self 11 12 def __exit__(sel... 阅读全文
posted @ 2019-07-24 17:09 _simpleSmile 阅读(189) 评论(0) 推荐(0) 编辑
上一页 1 ··· 5 6 7 8 9 10 11 下一页