CS170: Programming for the World Around Us - Dictionaries with Python

Activity Goals

The goals of this activity are:
  1. To associate data using the Python dictionary

Supplemental Reading

Feel free to visit these resources for supplemental background reading material.

The Activity

Directions

Consider the activity models and answer the questions provided. First reflect on these questions on your own briefly, before discussing and comparing your thoughts with your group. Appoint one member of your group to discuss your findings with the class, and the rest of the group should help that member prepare their response. Answer each question individually from the activity, and compare with your group to prepare for our whole-class discussion. After class, think about the questions in the reflective prompt and respond to those individually in your notebook. Report out on areas of disagreement or items for which you and your group identified alternative approaches. Write down and report out questions you encountered along the way for group discussion.

Model 1: Data Maps

Nouveau Dictionnaire Larousse page
Telefonbog ubt-1

Questions

  1. Consider the dictionary and phone book above. When you look something up in each of them, what are you looking up, and what are you looking for? What are the data types?
  2. What are some ways that we make these lookups easier? How are the data organized, and what part of the data is organized that way?
  3. A phone book maps ______ to ______, and a dictionary maps ______ to ______.
  4. In computing, we tend to say that we map keys to values. For the phone book and dictionary, what is the key, and what is the value?

Model 2: Dictionaries in Python

Questions

  1. What would you change in the program above to store the number of students enrolled in each course, instead of the instructor of each course?
  2. Suppose you are developing a web browser that accesses web pages. You want to cache the pages, so that you only access them once, to save on I/O, network calls, and your data plan. How might a HashMap help you to do this? What would be the key and the value?

Model 3: Complex Dictionaries in Python

Questions

  1. Add a few more courses to this dictionary.
  2. Write a program to print the instructor, the enrollment, and all the students in all classes.

Submission

I encourage you to submit your answers to the questions (and ask your own questions!) using the Class Activity Questions discussion board. You may also respond to questions or comments made by others, or ask follow-up questions there. Answer any reflective prompt questions in the Reflective Journal section of your OneNote Classroom personal section. You can find the link to the class notebook on the syllabus.