[Application] the basics of Python (21) Dictionary in the project (to store employee information)

# Recording information of employees: job number, name, title, department, salary 
Source = " 7782, CLARK, MANAGER, SALES, 5000 $ " \
          " 7934, MILLER, SALESMAN, SALES, 3000 $ " \
          " 7369, SMITH, ANALYST , s, 2000 " 

# 1. the number will be $ each employee data segmented (divided into three sets of data) (List type) EMP_LIST source.split = ( " $ " ) Print (EMP_LIST) # output: [ '7782, CLARK, MANAGER, SALES, 5000 ',' 7934, MILLER, SALESMAN, SALES, 3000 ',' 7369, SMITH, ANALYST, RESEARCH, 2000 ']
# statement all_emp used to store all employee information, key: number of employees, value: employee information all_emp = {}
# 2.Employee information stored in the dictionary for iin Range (0, len (EMP_LIST)):

  # 2.1 in accordance with the division number of each employee information (Type List) Employee
= EMP_LIST [I] .split ( " , " ) # 2.2 employee information key value pairs mode storage (Dictionary type) dic_emp = { ' Number ' : Employee [0], ' name ' : Employee [. 1], ' Job ' : Employee [2], ' Dept ' : Employee [. 3], ' the salary ' : Employee [4 ]} # 2.3 storage mode changes again, key as employee number, value, compared with the corresponding employee information (Dictionary type) all_emp [dic_emp [ ' number ']] =dic_emp
# 3. Number of employees view employee information in accordance with emp_no the INPUT = ( " Please enter the employee number: " ) IF emp_no in all_emp: emp = all_emp.get (emp_no) Print ( " Employee Number: {number}, Name: {name} working: {job}, departments: {dept}, salary: salary {} " .format_map (emp)) the else : Print ( " the employee number does not exist " )

 

Guess you like

Origin www.cnblogs.com/ac-chang/p/12620407.html