#处理员工数据
source = "7782,clark,manager,sales,5000$7934,miller,salesman,sales,3000"
source1 = source.split("$")
print(source1)
#保存所有解析后的员工信息,key是员工编号,value是信息
all_emp = {}
for i in range(0,len(source1)):
e=source1[i].split(",")
print(e)
#创建员工字典
employe = {'no':e[0],'name':e[1],'job':e[2],'department':e[3],'salary':e[4]}
print(employe)
all_emp[employe['no']]=employe
print(all_emp)
while True:
empno = input("请输入员工编号: ")
if empno in all_emp:
emp = all_emp.get(empno)
print("工号:{no},姓名:{name},岗位:{job},部门:{department},工资:{salary}".format_map(emp))
else:
print("请输入正确的工号")
文章名称:字典的应用
浏览路径:
http://cxhlcq.com/article/jdcojd.html