标签:
有序字典:
import collections
dic = collections.OrderedDict()
dic[‘a‘] = ‘a1‘
dic[‘b‘] = ‘b1‘
dic[‘c‘] = ‘c1‘
print(dic)
通过列表去像字典传输元素,以达到有顺序。
默认字典:
dic = collections.defaultdict(list)定义默认字典的元素为list。
#dic={}
a = [11,22,33,44,55,66,77,88,99]
for i in a:
if i >66:
dic[‘k1‘].append(i)
else:
dic[‘v2‘].append(i)
可命名元组:
print(dic)name_tuple=collections.namedtuple(‘name_tuple‘,[‘x‘,‘y‘,‘z‘])
tuple1=name_tuple(11,22,33)
print(tuple1.x)
print(tuple1.y)
标签:
原文地址:http://www.cnblogs.com/dahuige/p/5143054.html