Skip to main content
Noble Desktop/2 min read

Dictionary in Python

Python Workflow

1

Set Up venv

python -m venv .venv — isolated environment per project.

2

Install Dependencies

pip install -r requirements.txt — pin versions for reproducibility.

3

Write & Test

Write functions; test with pytest as you go.

4

Run & Deploy

python script.py locally, deploy to your platform of choice.

Master Python at Noble Desktop

Noble Desktop's Python Programming Immersive covers AI APIs, data analysis, and modern Python development.

In this video, we're going to look at how to manage data using Dictionary in Python

Video Transcription

Hi, My Name is Art and I Teach Python at Noble Desktop. in This Video, I'll Explain Dictionaries to You. Remember That Python Has Built-in Data Types Like Integers, Floats, Strings, and Lists. How Do You Initialize a Dictionary?

First, come up with a variable name, like 'd', and use curly braces. To check if it's a dictionary, use the 'type' function and it should return 'dictionary'.

Before I give you a formal definition of a dictionary, let me show you how we can populate the dictionary with data. Suppose this is my phone book, and I have a friend named John. John is the key, and 'Manhattan' is the value. We can add another friend, Mary, her phone number, and also Mark and his phone number.

A dictionary is a completely different collection than what we've seen so far—it is a collection of items, where each item has a key and a value, separated by a colon and each item separated by a comma. Keys must be unique.

It's easy to update values—just use the key and assign a new value. To see all keys, use the 'keys' function. To fetch a value, use the key in square brackets. To update a value, use the key in square brackets and assign a new value.

Watch my other videos to learn how to use a 'for' loop to iterate through a dictionary.