Python Dictionaries

Dictionary is an unordered collection of key-value pairs. "dict" is a built-in Python class that represents a dictionary object.

The contents of a dict can be written as a series of key:value pairs within braces { } e.g. dict = {key1:value1, key2:value2, ... }.

The "empty dict" is just an empty pair of curly braces {}.

The keys will appear in an arbitrary order. The methods dict.keys() and dict.values() return lists of the keys or values.

dict.png

Add a new key value pair to dictionary

Remove value from dictionary using its key

You can also use 'pop' to remove the value from dictionary

Difference between del and pop()

Removing an item from a dictionary with a non-existent key, gives a KeyError exception