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:
- Next, we can utilize the
for
..in
loop to print each of the record's data withinemployee
:for employee in employees: print(employee)
- To have the data presented in a structured version of the
employee
record, add the following lines of code:for employee in employees: print("Name:", employee[0]) print("Age:", employee[1]) print("Department:", employee...