Python(54)_大于66的分组存放在字典里

#-*-coding:utf-8-*-
'''
分别放在列表里
'''
li = [11,22,33,44,55,66,77,88,99,110]
result ={}
for row in  li:
    if row>66:
        if 'key1' not in result:  # 如果不在,就创建键值对,空列表
            result['key1'] =[]
        result['key1'].append(row)
    else:
        if 'key2' not in result:  # 如果不在,就创建键值对,空列表
            result['key2'] = []
        result['key2'].append(row)
print(result)

猜你喜欢

转载自www.cnblogs.com/sunnybowen/p/10230970.html