python 字典学习

 大于20都属于k1,小于等于属于k2

dic = {}
li = [13,2,33,145,23,7,55,45,88,]
for i in li:
    if i > 20:
        if 'k1' in dic.keys():
            dic['k1'].append(i)
        else:
            dic['k1'] = [i,]
    else:
        if 'k2' in dic.keys():
            dic['k2'].append(i)
        else:
            dic['k2'] = [i,]

print(dic)

 

posted @ 2016-09-30 23:07  JonyQ  阅读(186)  评论(0编辑  收藏  举报