Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Creating a Dictionary | Dictionary
Python Data Structures
course content

Course Content

Python Data Structures

Python Data Structures

1. List
2. Dictionary
3. Tuple
4. Set

bookCreating 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:

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

Check out the code to make this dictionary.

12
student = {'first name': 'Ann', 'last name': 'Elliot', 'city': 'New York'} print(student)
copy

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.

12
countries = {4: 'Belgium', 2: 'Finland', 7: 'China', 5: 'Cyprus'} print(countries)
copy

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

It's time to practice!

Task

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.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 1
toggle bottom row

bookCreating 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:

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

Check out the code to make this dictionary.

12
student = {'first name': 'Ann', 'last name': 'Elliot', 'city': 'New York'} print(student)
copy

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.

12
countries = {4: 'Belgium', 2: 'Finland', 7: 'China', 5: 'Cyprus'} print(countries)
copy

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

It's time to practice!

Task

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.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 1
toggle bottom row

bookCreating 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:

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

Check out the code to make this dictionary.

12
student = {'first name': 'Ann', 'last name': 'Elliot', 'city': 'New York'} print(student)
copy

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.

12
countries = {4: 'Belgium', 2: 'Finland', 7: 'China', 5: 'Cyprus'} print(countries)
copy

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

It's time to practice!

Task

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.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

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

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

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

Check out the code to make this dictionary.

12
student = {'first name': 'Ann', 'last name': 'Elliot', 'city': 'New York'} print(student)
copy

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.

12
countries = {4: 'Belgium', 2: 'Finland', 7: 'China', 5: 'Cyprus'} print(countries)
copy

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

It's time to practice!

Task

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.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Section 2. Chapter 1
Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
some-alt