Editor settings

General settings

Save settings

Learn to program with Python

Looping Through Keys in a Dictionary #

Let's take a look at an example of looping through dictionary data:

my_student = {"name": "James", "age": 10, "gender": "M"}
for i in my_student:
    print(i)
Output
# name
# age
# gender

We can see that the data printed out are the keys of the dictionary. We can use this to access the values of the dictionary:

my_student = {"name": "James", "age": 10, "gender": "M"}
for key in my_student:
    print(my_student[key])
Output
# James
# 10
# M

Exercise #

Loop through the given dictionary person and append its values to the list properties.

Tests #

  • The list properties should contain "George", 35, and "M"
Output will be displayed here