D. Dictionary Methods

This appendix lists the methods of the dict type. It does not cover functions that also may be used with this type, such as len. For those, see Appendix B.

In the syntax displays that head each section, square brackets are not intended literally but indicate optional items.

Table D.1. Most Commonly Used Dictionary Methods.

To Do The Following Task:

Call This Method:

Add key/value pairs from another collection


Clear all contents of dictionary


Copy all contents of another dictionary


Delete a key and associated value


Get a value by key; return a default value (such as None) if the key is not found


Get a sequence containing all associated values


Get a sequence containing all ...

Get Supercharged Python: Take Your Code to the Next Level, First Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.