Course Content
Python Data Structures
Python Data Structures
Creating 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:
Key | Value |
'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!
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.
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.
Everything was clear?
Creating 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:
Key | Value |
'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!
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.
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.
Everything was clear?
Creating 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:
Key | Value |
'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!
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.
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.
Everything was clear?
A dictionary is a data structure that stores unordered key-value pairs.
Imagine you need to create a dictionary called student
with these pairs:
Key | Value |
'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!
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.