# -*- coding:utf-8 -*-
#常规方法需要指定字典值类型
dic = {'k1': []}
dic['k1'].append('alex')
#通过collections中的defaultdict()类,为字典值创建默认类型
import collections
dic = collections.defaultdict(list)#创建字典dic,值默认类型为列表
dic['k1'].append('alex')
all_list = [11, 22, 33, 44, 55, 66, 77, 88, 99]
dic1 = {}
for i in all_list:
if i < 66:
if 'k1' in dic1.keys():
dic1['k1'].append(i)
else:
dic1['k1'] = [i]
else:
if 'k2'in dic1.keys():
dic1['k2'].append(i)
else:
dic1['k2'] = [i]
print(dic1)
all_list = [11, 22, 33, 44, 55, 66, 77, 88, 99]
dic1 = collections.defaultdict(list)
for i in all_list:
if i < 66:
dic1['k1'].append(i)
else:
dic1['k2'].append(i)
print(dic1)