1/16
Key vocabulary and essential operations covering Python dictionaries, common dictionary methods, iteration using view objects, and nested dictionary structures.
Dictionary (dict)
A container object in Python that stores references to objects as key-value pairs, where elements maintain insertion order as of Python 3.7.
Key-value pair
An association where each unique key in a dictionary references and maps to a specific value, analogous to a word and its definition.
my_dict[key]
An indexing operation that retrieves the value associated with the specified key in a dictionary.
my_dict[key] = value
An operation that adds a new entry if the key does not already exist, or modifies the existing entry's value if the key is present.
del my_dict[key]
An operation that deletes the entry with the specified key from a dictionary.
key in my_dict
An expression that tests for the existence of a specified key within a dictionary, returning True if present and False otherwise.
Dictionary method
A function provided by the dict type that operates directly on a specific dictionary object to perform operations such as modifying entries, querying data, or merging.
my_dict.clear()
A dictionary method that removes all items from the dictionary, leaving it empty.
my_dict.get(key, default)
A dictionary method that reads and returns the value of the key; if the key does not exist, it returns the specified default value.
my_dict1.update(my_dict2)
A dictionary method that merges my_dict1 with another dictionary my_dict2, overwriting existing entries in my_dict1 if matching keys exist in my_dict2.
my_dict.pop(key, default)
A dictionary method that removes and returns the value associated with the specified key; if the key does not exist, it returns the provided default value.
View object
A read-only object produced by dict methods (items(), keys(), or values()) that dynamically reflects changes to the dictionary and yields items on demand to conserve memory without supporting direct indexing.
dict.items()
A dictionary method that returns a view object yielding (key, value) tuples for all entries in the dictionary.
dict.keys()
A dictionary method that returns a view object yielding all the keys present in the dictionary.
dict.values()
A dictionary method that returns a view object yielding all the values present in the dictionary.
Nested dictionary
A dictionary structure where the value of an entry is itself another dictionary, accessed using consecutive bracket pairs like dict[key1][key2].
Data structure
A method of organizing data in a logical and coherent fashion, supported by containers like lists and arbitrary levels of nested dictionaries.