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

update

Clear all contents of dictionary

clear

Copy all contents of another dictionary

copy

Delete a key and associated value

pop

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

get

Get a sequence containing all associated values

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 live online training, plus books, videos, and digital content from nearly 200 publishers.