First, Practice:
#!usr/bin/env python
#-*-Coding:utf-8 _*-
"""
@author: Administrator
@file: dictionary.py
@time: 2017/11/19
"""
""
Have the following set [11,22,33,44,55,66,77,88,99,110,121,132,143,154,165,176,187], save all values greater than 66 in the first key of the dictionary, save the value less than 66 in the value of the second key
That is: {' K1 ': greater Than, ' K2 ': Less than 66}
‘‘‘
##### #方法一
#dic = {}
#all_list = [11,22,33,44,55,66,77,88,99,110,121,132,143,154,165,176,187]
#for I in All_list:
# If I > 66:
# 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[' K1 ')
#print (dic[' K2 ')
#方法二,
All_list= [ One, A, -, -, -, the, the, the, About, the,121, the,143,154,165,176,187]
Dic= {' K1 ':[],' K2 ':[]}
forIteminchAll_list:
ifItem> the:
dic["K1"].append (item)
Else:
dic["K2"].append (item)
Print(dic[' K1 '])
Print(dic[' K2 '])
This article from the "Linux" blog, reproduced please contact the author!
Python essay (c), Python basics