Dictionary are unordered collections of unique values stored in (Key-Value) pairs. Learn how to create, access, and modify a dict in Python and all other operations we can perform on a dictionary
In Python version 3.7 and onwards, dictionaries are ordered. In Python 3.6 and earlier, dictionaries are unordered.
Python dictionary represents a mapping between a key and a value. In simple terms, a Python dictionary can store pairs of keys and values. Each key is linked to a specific value. Once stored in a dictionary, you can later obtain the value using just the key.
For example, consider the Phone lookup, where it is very easy and fast to find the phone number(value) when we know the name(Key) associated with it.

The following are the properties of a dictionary.
- Mutable: Dictionaries can be modified after creation—you can add, update, or remove key-value pairs at any time.
- Ordered (Python 3.7+): Dictionaries maintain the insertion order of key-value pairs, so items are returned in the order they were added.
- Heterogeneous: Dictionaries can contain keys and values of different types—strings, integers, booleans, lists, or even other dictionaries.
- Unique Keys: Keys in a dictionary must be unique. If the same key is assigned more than once, the most recent value will overwrite the previous one.
Why use a dictionary?
- Dictionaries are ideal for storing data that needs to be looked up by a label or identifier, rather than by position.
- They provide fast access to values through keys using hashing, making retrieval very efficient.
- Their ability to store diverse data types as values increases their flexibility.
- The unique key constraint ensures that each piece of data is clearly defined and not accidentally overwritten unless explicitly intended.
- Their mutable nature makes them perfect for dynamic datasets where changes are frequent.
Table of contents
- Characteristics of dictionaries
Creating a dictionaryEmpty DictionaryAccessing elements of a dictionaryGet all keys and valuesIterating a dictionaryFind a length of a dictionaryAdding items to the dictionarySet default value to a keyRemoving items from the dictionaryChecking if a key exists- Join two dictionary
- Using update() method
- Using **kwargs to unpack
- Join two dictionaries having few items in common
- Copy a Dictionary
- Copy using the assignment operator
- Nested dictionary
- Add multiple dictionaries inside a single dictionary
- Sort dictionary
- Dictionary comprehension
- Python Built-in functions with dictionary
- Summary of dictionary operations