1. 程式人生 > >Python(54)_大於66的分組存放在字典裡

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)