{}
). A colon (:
) separates each key from its associated value:dict()
function. The argument to dict()
should be a sequence of key-value pairs. A list of tuples works well for this:mlb_team
:get()
method.get()
is that it returns None
instead of KeyError
, if the key is not found.pop()
. This method removes an element with the provided key and returns the value.popitem()
can be used to remove and return an arbitrary or last element (key, value) from the dictionary. All the elements can be removed at once using the clear()
method.del
keyword to remove individual elements or the entire dictionary itself.pop()
pop()
method expects a location of the key and value pair. Index in dictionary starts from ONE.popitem()
popitem()
remove the last key and value pair from the dictionary.del
del
method to delete a key and value pair based on the index location, remember index starts from ONE in the dictionaries. You can use del
to delete the whole dictionary as well.clear()
clear()
method can be use to delete all key and pair values in the dictionary, it returns an empty dictionary.None
).None
).KeyError
.KeyError
if the dictionary is empty.None
).for
statement inside curly brackets {}
.if
statement can filter out items to form the new dictionary.