11.9. Debugging¶
Lists, dictionaries and tuples are known generically as data structures. In this chapter, we have started to see compound data structures, like lists of tuples and dictionaries with tuples as keys and lists as values.
Compound data structures are useful, but they are prone to shape errors; that is, errors caused when a data structure has the wrong type, size, or composition, or perhaps you write some code and forget the shape of your data and introduce an error. For example, if you are expecting a list containing one integer and I just give you an integer that isn’t in a list, it won’t work.
- Read, retreat, run, ruminate
- Correct! As shown in Chapter 1, these are the best ways to go about discovering bugs in your code.
- Read, google, run, ruminate
- Incorrect! While Google is very useful for programmers, it's not one of the debugging steps we reviewed in Chapter 1. Try again.
- Email your GSI for help
- Incorrect! While you can always reach out to your GSI with questions, always make sure to first try and find the bug yourself. Try again.
11-9-1: When an error is present in your code, what should you do to help discover the bug?
- Lists of tuples
- Correct! Lists of tuples are a type of compound data structure.
- Lists
- Incorrect! Lists are a type of data structure, but a list by itself isn't compound. Try again.
- Tuples
- Incorrect! Tuples are a type of data structure, but a tuple by itself isn't compound. Try again.
- Dictionaries with tuples for keys
- Correct! A dictionary with tuples for keys is another type of compound data structure.
11-9-3: Which of the following are examples of compound data structures? (Select all that apply)