You have now used both lists and dictionaries in Python. This lab is all about how to combine those two data structures for even more possibilities.
Ensure that you are signed into GitHub
Open the assignment: Project 6 - Shopping List
Open lab2.py
Suppose we want to keep track of a student's grades in different subjects.
We could use a dictionary where the keys are the subjects and the values are lists of grades.
Now suppose we want to keep track of a group of students, each with a name and an age. This is a good use case for a list of dictionaries.
You can take this as far as you need to. Next term we will consider another way to structure data and programs - Object Oriented Programming.
For now, this can be quite a powerful way to structure your data as your programs become more advanced.
This code iterates over each student in the students list. For each student, it prints out the student's name and their Maths grades. The student's name is accessed with student['name'], and their Maths grades are accessed with student['grades']['math'].
Complete the following requirements:
Create a list of dictionaries called contacts that contains contact information.
Each dictionary will represent a contact and contains:
Name, Address, Email and a list of phone numbers. Make up at least 3 contacts.
Add an extra phone number to one of your contacts
Add a new contact
Delete a contact
Print out the entire contacts list in a nice format
Press Ctrl + F5 to run the program or open a terminal and type python lab2.py
You should now know how to combine lists and dictionaries in Python.
Let's wrap up this lab by pushing our code to GitHub:
Enter a commit message. E.g. "Lab 2 complete"
Press Commit to main
Press Push origin