标签:
#!/usr/bin/python #coding:utf8 #将列表中大于66的数字存在key1中,小于66的数字存在key2中 List = [11,22,33,44,55,66,77,88,99] dic = {} for i in List: if i <= 66: if ‘k1‘ in dic.keys():#先判断是否存在k1键 dic[‘k1‘].append(i)#如果存在k1,k1对应的值为列表,将数字追加到列表中 else: dic[‘k1‘] = [i,]#如果不存在k1,则添加k1,并给k1添加第一个元素 else: if ‘k2‘ in dic.keys(): dic[‘k2‘].append(i) else: dic[‘k2‘] = [i,] print dic
标签:
原文地址:http://www.cnblogs.com/ahaii/p/5126677.html