Looping through dictionary values #
If we only need to access the values of the dictionary, we can use the values() method instead.
Here is an example looping through a dictionary values with values() method:
my_student = {"name": "James", "age": 10, "gender": "M"}
print(my_student.values()) # dict_values(['James', 10, 'M'])
for value in my_student.values():
print(value)
Exercise #
Loop through the dictionary person and add its values to the list properties.
Tests #
- List
propertiesshould contain"George" - List
propertiesshould contain35 - List
propertiesshould contain"M"
Getting Started with Python
Data Types
Python Functions
Statements in Python
Basic Debugging in Python
Basic Algorithm
Object-Oriented Programming
Error Handling
Intermediate Algorithm
Python Modules