course content

Course Content

Python Data Structures

Creating a DictionaryCreating a Dictionary

A dictionary is a data structure that stores unordered key-value pairs.

Imagine you need to create a dictionary called student with these pairs:

'first name''Ann'
'last name''Elliot'
'city''New York'

Check out the code to make this dictionary.

In a dictionary, you can use any immutable data type for a key. For instance, the dictionary we just looked at has strings as keys. Now, let's whip up a dictionary using numbers as keys.

Remember, the value associated with a specific key can be anything — strings, numbers, lists, and so on.

It's time to practice!


Your task is to craft this dictionary:

'Colorado':'Rockies', 'Boston':'Red Sox', 'Minnesota':'Twins'.

Here, Colorado is a key, while Rockies is its corresponding value, and so forth.

Everything was clear?

Section 2. Chapter 1
toggle bottom row