Dictionaries

Look into the key features of the dictionary data structure.

Structure

A dictionary has a slightly more complex structure than a list or tuple. When we think of a dictionary, we imagine a vast book containing words and their meanings. In simpler terms, information is stored in pairs of words and meanings. Python’s dictionary data structure follows the same structure. A dictionary stores key-value pairs, where each unique key is an index that holds the value associated with it. Dictionaries are unordered because the entries are not stored in a linear structure. In Python, we must put the dictionary’s content inside curly brackets, {}:

Press + to interact

A key-value pair is written in the following format:

key:value

Creating a dictionary

Creating a dictionary in Python is straightforward. Here's how to create an empty dictionary and a simple phone_book ...