Back Navigation Next Navigation Conceptual Review (page 40 of 55)

With a dictionary object, we may loop over just the keys using .keys(), just the values using .values(), or both the keys & values using .items(). We will probably use .items() most frequently because that method gives us both the keys and values. However, looping over just the values might be helpful if we want to, say, grab the values to perform a mean, median, or standard deviation calculation where we do not care about the matching keys. Looping over the keys may also be useful if the keys represent, say, primary keys in a database and we want to ensure that we have all the keys.

Dictionaries