Course Content
Python Data Structures
Python Data Structures
Extraction of Information
Let's build a dictionary called student
.
student = {'first name': 'Ann', 'last name': 'Elliot', 'city': 'New York'} print(student)
This dictionary includes three key-value pairs:
Key | Value |
'first name' | 'Ann' |
'last name' | 'Elliot' |
'city' | 'New York' |
In the dictionary, you can retrieve an item using its key. Here's an example.
student = {'first name': 'Ann', 'last name': 'Elliot', 'city': 'New York'} city_of_student = student['city'] print(city_of_student)
In the code provided, Python searches for the value associated with the 'city'
key in the student
dictionary and assigns this value to the city_of_student
variable.
Time to get hands-on!
Task
You're working with the following dictionary:
Display the values for the keys Turkey
and Malta
.
Task
You're working with the following dictionary:
Display the values for the keys Turkey
and Malta
.
Everything was clear?
Extraction of Information
Let's build a dictionary called student
.
student = {'first name': 'Ann', 'last name': 'Elliot', 'city': 'New York'} print(student)
This dictionary includes three key-value pairs:
Key | Value |
'first name' | 'Ann' |
'last name' | 'Elliot' |
'city' | 'New York' |
In the dictionary, you can retrieve an item using its key. Here's an example.
student = {'first name': 'Ann', 'last name': 'Elliot', 'city': 'New York'} city_of_student = student['city'] print(city_of_student)
In the code provided, Python searches for the value associated with the 'city'
key in the student
dictionary and assigns this value to the city_of_student
variable.
Time to get hands-on!
Task
You're working with the following dictionary:
Display the values for the keys Turkey
and Malta
.
Task
You're working with the following dictionary:
Display the values for the keys Turkey
and Malta
.
Everything was clear?
Extraction of Information
Let's build a dictionary called student
.
student = {'first name': 'Ann', 'last name': 'Elliot', 'city': 'New York'} print(student)
This dictionary includes three key-value pairs:
Key | Value |
'first name' | 'Ann' |
'last name' | 'Elliot' |
'city' | 'New York' |
In the dictionary, you can retrieve an item using its key. Here's an example.
student = {'first name': 'Ann', 'last name': 'Elliot', 'city': 'New York'} city_of_student = student['city'] print(city_of_student)
In the code provided, Python searches for the value associated with the 'city'
key in the student
dictionary and assigns this value to the city_of_student
variable.
Time to get hands-on!
Task
You're working with the following dictionary:
Display the values for the keys Turkey
and Malta
.
Task
You're working with the following dictionary:
Display the values for the keys Turkey
and Malta
.
Everything was clear?
Let's build a dictionary called student
.
student = {'first name': 'Ann', 'last name': 'Elliot', 'city': 'New York'} print(student)
This dictionary includes three key-value pairs:
Key | Value |
'first name' | 'Ann' |
'last name' | 'Elliot' |
'city' | 'New York' |
In the dictionary, you can retrieve an item using its key. Here's an example.
student = {'first name': 'Ann', 'last name': 'Elliot', 'city': 'New York'} city_of_student = student['city'] print(city_of_student)
In the code provided, Python searches for the value associated with the 'city'
key in the student
dictionary and assigns this value to the city_of_student
variable.
Time to get hands-on!
Task
You're working with the following dictionary:
Display the values for the keys Turkey
and Malta
.