2. Python Structures
Activity 6: Using a Nested List to Store Employee Data
Solution:
- Begin by creating a list, adding data, and assigning it to
employees:employees = [['John Mckee', 38, 'Sales'], ['Lisa Crawford', 29, 'Marketing'], ['Sujan Patel', 33, 'HR']] print(employees)
You should get the following output:
Figure 2.31: Output when we print the content of employees
- Next, we can utilize the
for..inloop to print each of the record's data withinemployee:for employee in employees: print(employee)
Figure 2.32: Output when printing each of the records inside employees
- To have the data presented in a structured version of the
employeerecord, add the following lines of code:for employee in employees: print("Name:", employee[0]) print("Age:", employee[1]) print("Department:", employee...