标签:python
需求:把1到100的列表拆分成字典中两个键值对,k1和k2。
#!/usr/bin/python
num = {}
all_list = []
for nu in range(1101):
all_list.append(nu)
for i in all_list:
if i < 75:
if ‘k1‘ in num.keys():
num[‘k1‘].append(i)
else:
num[‘k1‘] = [i, ]
else:
if ‘k2‘ in num.keys():
num[‘k2‘].append(i)
else:
num[‘k2‘] = [i,]
print num
标签:python
原文地址:http://qikang.blog.51cto.com/1504256/1856287