Part 13 - Dictionaries

In this section you will be introduced to a 'dictionary' in Python. It behaves very similarly to a list, however, its elements are not accessed by and index number, but rather a meaningful keyword called a 'Key' that the programmer defines.

What do do/Hand in?

1. Read through and do "Part 13 - Dictionaries"

2. Modify the Dodger.py program by adding your own graphics. Try to add some of your own features.

Submit:

1. Your modified Dodger.py program.


Hints and FAQ's

1. If you want to iterate through your dictionary in a predictable order, make a list that contains the dictionary keys in the order you would like to retrieve them. Iterate through the items in this list, and use them as the keys in your dictionary.

2. Notice that in Dodger.py, functions are used a fair bit. This is a nice way to reduce the size of your program.

3. Extra features: Notice in Dodger.py that the 'x' and 'z' keys perform 'cheats'. Either modify them, or add your own.

4. It is important to notice how Dictionaries are used here effectively in Dodger.py. Since each of the many items falling (the baddies) do not necessarily share the same properties (how big they are, how fast they are falling and their location), it makes sense to use a Dictionary to store these three values for each baddie. By using an appropriate Key (in this case 'surface'; the re-sized image, 'rect'; location/size and 'speed'; rate at which it is falling) that indicates what is stored there it makes it easy to get the data we want. We can then use a list to store all of our baddies, and iterate through the list and easily access the desired property using the appropriate key.