1、有如下值集合 [11,22,33,44,55,66,77,88,99,90...],将所有大于 66 的值保存至字典的第一个key中,将小于 66 的值保存至第二个key的值中。
即: {'k1': 大于66的所有值, 'k2': 小于66的所有值}
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 num = set([11,22,33,44,55,66,77,88,99,90]) 2 dict1 = {"K1":1,"K2":2} 3 k1 = [] 4 k2 =[] 5 for i in num: 6 if i >= 66: 7 k1.append(i) 8 dict1["K1"] =k1 9 else: 10 k2.append(i) 11 dict1["K2"] =k2 12 13 print(dict1)