昨日回顾

#常用模块
# 时间模块
# time
#time 是datetime 的底层模块
#时间戳 localtime/gmtime()--->结构化 strftime---->格式化
# 时间戳 <---mktime 结构化 <----strptime格式化
#时间戳 是一样的 只不过 转的不一样 gm转的是英国的 local 是中国的
#time.time()时间戳
#结构化=time.localtime(时间戳)
#字符串=time.strftime(结构化)
#datetime
#事件对象
#时分秒
#计算时间差\
# t = datetime.datetime.now()#跟时间相关的 文件句柄差不多
# print(t.date())
#collections
#Counter
#可命名元组 namedtuple
#双端队列 deque
#默认字典 defaultdict
from collections import Iterable,Iterator
# 可迭代对象 迭代器 了不起的collections 很多东西
print(isinstance(range(10),Iterable))
print(isinstance(range(10),Iterator))
print(isinstance(open('a','w'),Iterator))
print(isinstance(open('a','w'),Iterable))
# True
# False
# True
# True
from collections import defaultdict
def func():
return 5
dic = defaultdict(lambda :5)
dic1 = defaultdict(func)
dic = defaultdict(set)
dic = defaultdict(list)
print(dic['a'])
print(dic1['a'])

#双端队列 和列表的区别 不表现在用法上
#效率 底层的 数据结构  学了东西 区别和联系 好记
#123456 1之前insert一个值 全部往后挪 列表 删了一个 1 都往上 挪
# 用列表 用 append pop() 专业 非常快 用pop(0)这样的非常慢
# 双端 0 next 1 next 2 next 断一个连一个 删除和添加一个非常高
# 列表 找值速度也非常快(索引) 最后一个增添快 ‘’
# 双端只是从中间插入 或者 删除比较频繁的时候 列表 单纯的append pop 和找值时
from collections import deque

d = deque([1,2,3,4])
print(d[1])

猜你喜欢

转载自www.cnblogs.com/Doner/p/10569850.html