Editor settings

General settings

Save settings

Learn to program with Python

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 properties should contain "George"
  • List properties should contain 35
  • List properties should contain "M"
Output will be displayed here