笔记 # -*- coding:utf-8 -*- #需求:一个列表里大于66的元素添加字典的第二个key k2里,小于66的添加第一个 key k1里 li = [1,2,3,4,5,6,67,7,8,98,11,22,33,44,55,66,77,88,99,111,222,333,444,555,666] dic = {} for item in li: if item >60: if 'k2' in dic.keys(): dic['k2'].append(item) else: dic