Once data is in a dictionary, you will often need to walk through all of it: print a report, total the values, or find the largest entry. Dictionaries give you three views of their contents. d.keys() returns the keys, d.values() returns the values, and d.items() returns the key-value pairs as two-item tuples. These are view objects, not lists: they reflect later changes to the dictionary, and you can loop over them, test membership in them or convert them with list(). Printing one shows something like dict_keys(['a', 'b']), and views cannot be indexed, so d.keys()[0] raises TypeError; use list(d.keys())[0] if you really need a position.
Keep reading for free
Create a free StudyToCert account to read the rest of this lesson: 7 more sections, 6 key terms, a real-world example, an exam tip and self-check questions. Every lesson, lab and practice test is free with an account.