When to use a dictionary in Python | Basics

Use a dictionary data type when the data has a unique reference that can be associated with the value in Python. A dictionary is a mapping, which means the relation between keys and values is not symmetrical. For example, it’s tricky to fetch a key by a known value.

dict – if you require to relate values with keys

Note: dictionaries are mutable, you can’t modify them in the first place.

Example use a dictionary in Python

Simple example code dict associates each key with a value, while list and set just contain values: very different use cases.

employees = {"1": "George", "2": "Nell", "3": "Jasper"}



When to use a dictionary in Python

Do comment if you have any doubts and suggestions on this Python basic tutorial.

Note: IDE: PyCharm 2021.1.3 (Community Edition)

Windows 10

Python 3.7

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.