Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Incrementally Building a Dictionary

Give Feedback

Defining a dictionary using curly braces and a list of key-value pairs is fine if you know all the keys and values in advance. But what if you want to build a dictionary on the fly?

You can start by creating an empty dictionary, which is specified by empty curly braces. Then you can add new keys and values one at a time. Once the dictionary is created in this way, its values are accessed the same way as any other dictionary. Retrieving the values in the sublist or subdictionary requires an additional index or key.

You can use dictionaries for a wide range of purposes because there are so few limitations on the keys and values that are allowed. But there are some, as you’ll see in the next lesson.

Minh Pham on March 22, 2020

Hello Paul,

Could you please provide text of what your wrote in the video so that we can try it out ourselves

BR Minh

John Kinder on Aug. 31, 2020

Anyone who has a Trek bike is OK in my book. ;)

Become a Member to join the conversation.