模块collections,time,random,sys模块
一、collections模块 # from collections import OrderedDict# d = OrderedDict()# d['a'] = 1# d['z'] = 2# d['b'] = 3# print(d)## d['z'] = 0# print(d)# {'apple':100,'computer':10000}# 默认字典# 有如下值集合 [11,22,33,44,55,66,77,88,99,90...],# 将所有大于 66 的值保存至字典的第一个key中,# 将小于 66 的值保存至第二个key的值中。# dic = {}# l = [11,22,33,44,55,66,77,88,99,90]# for i in l:# if i>66:# if dic.get('k1'):# dic['k1'].append(i)# else:# dic['k1'] = [i]# elif i<66:# if dic.get('k2'):# dic['k2'].append(i)# else:# dic['k2'] = [i]# print(dic)from collections import defaultdict# d = defaultdict(set)# print(d)# print(d['a'])# d['b'] = 10# print(d