Sample Video Frame

Created by Zed A. Shaw Updated 2024-02-17 04:54:36
 

Exercise 17: Dictionary

You should be familiar with Python's dict class already. Any time you write code like this:

cars = {'Toyota': 4, 'BMW': 20, 'Audi': 10}

you're using a dict to associate the models of cars ('Toyota', 'BMW', 'Audi') to the total you have (4, 20, 10). Using this data structure should be second nature to you by now, and you probably don't even think about how it works. In this exercise you will learn how a dict works by implementing your very own Dictionary from data structures you already created. Your goal in this exercise is to implement your own version of a Dictionary based on code I've written here.

Exercise Challenge

In this exercise you are going to fully document and understand a piece of code I've written and then write your own version of it from memory as best you can. The purpose of this exercise is to learn to dissect and understand a complicated piece of code. It is also important to be able to internalize, or memorize, what goes into creating a simple data structure like a Dictionary. The best way I've found to learn to dissect and understand a piece of code is to reimplement it based on your own study and memorization.

Think of this as a "Master Copy" class. A Master Copy comes from painting, where you take a painting created by someone better than you and attempt to make a copy of it. Doing this teaches you how that person painted and improves your skills. Code and paintings are similar in that all the information is right there ready to copy, so you can easily learn from someone else by just copying their work.

Previous Lesson Next Lesson

Register for Learn More Python the Hard Way

Register today for the course and get the all currently available videos and lessons, plus all future modules for no extra charge.