Course Content
Python Data Structures
Python Data Structures
Adding Items
Let's build a dictionary named student
.
student = {'first name': 'Ann', 'last name': 'Elliot', 'city': 'New York'} print(student)
Here's how you can add a key-value pair to a dictionary.
student = {'first name': 'Ann', 'last name': 'Elliot', 'city': 'New York'} student['country'] = 'USA' print(student)
The student
dictionary includes these pairs:
Key | Value |
'first name' | 'Ann' |
'last name' | 'Elliot' |
'city' | 'New York' |
'country' | 'USA' |
Note
Single
' '
and double" "
quotes in Python are interchangeable and equivalent.
Task
- Construct the following dictionary:
'name': 'Max', 'position': 'data scientist', 'level': 'junior'
; - To the existing dictionary, append a new key named
experience
(as a string) with the value of1
.
Thanks for your feedback!
Adding Items
Let's build a dictionary named student
.
student = {'first name': 'Ann', 'last name': 'Elliot', 'city': 'New York'} print(student)
Here's how you can add a key-value pair to a dictionary.
student = {'first name': 'Ann', 'last name': 'Elliot', 'city': 'New York'} student['country'] = 'USA' print(student)
The student
dictionary includes these pairs:
Key | Value |
'first name' | 'Ann' |
'last name' | 'Elliot' |
'city' | 'New York' |
'country' | 'USA' |
Note
Single
' '
and double" "
quotes in Python are interchangeable and equivalent.
Task
- Construct the following dictionary:
'name': 'Max', 'position': 'data scientist', 'level': 'junior'
; - To the existing dictionary, append a new key named
experience
(as a string) with the value of1
.
Thanks for your feedback!
Adding Items
Let's build a dictionary named student
.
student = {'first name': 'Ann', 'last name': 'Elliot', 'city': 'New York'} print(student)
Here's how you can add a key-value pair to a dictionary.
student = {'first name': 'Ann', 'last name': 'Elliot', 'city': 'New York'} student['country'] = 'USA' print(student)
The student
dictionary includes these pairs:
Key | Value |
'first name' | 'Ann' |
'last name' | 'Elliot' |
'city' | 'New York' |
'country' | 'USA' |
Note
Single
' '
and double" "
quotes in Python are interchangeable and equivalent.
Task
- Construct the following dictionary:
'name': 'Max', 'position': 'data scientist', 'level': 'junior'
; - To the existing dictionary, append a new key named
experience
(as a string) with the value of1
.
Thanks for your feedback!
Let's build a dictionary named student
.
student = {'first name': 'Ann', 'last name': 'Elliot', 'city': 'New York'} print(student)
Here's how you can add a key-value pair to a dictionary.
student = {'first name': 'Ann', 'last name': 'Elliot', 'city': 'New York'} student['country'] = 'USA' print(student)
The student
dictionary includes these pairs:
Key | Value |
'first name' | 'Ann' |
'last name' | 'Elliot' |
'city' | 'New York' |
'country' | 'USA' |
Note
Single
' '
and double" "
quotes in Python are interchangeable and equivalent.
Task
- Construct the following dictionary:
'name': 'Max', 'position': 'data scientist', 'level': 'junior'
; - To the existing dictionary, append a new key named
experience
(as a string) with the value of1
.