Dictionaries
A dictionary is a collection of ordered key-value pair items.
The values can be of any type: strings, numbers, dictionaries, lists, objects, ...
Use braces ({}) to create a dictionary.
Use commas to separate items in the dictionary.
Empty dictionary:
A dictionary with one key-value pair:
A dictionary with multiple key-value pairs:
Accessing keys in a Dictionary:
Accessing a key that doesn't exist throws an error:
Using the get function (return default/custom value if the key doesn't exist):
Adding new key-value pairs:
Modifying values in a dictionary:
Removing key-value pairs:
Looping through all key-value pairs:
Looping through all the keys in a dictionary:
Looping through all the keys in a dictionary in a particular order:
Looping through all the values in a dictionary:
Looping through all the unique values in a dictionary:
List of dictionaries: