Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

Andrew BoosHartig
1,820 PointsExpanding more on manipulating dictionaries and converting them for data manipulation.
Feel free to paste and play around with these as separate pieces by commenting some out.
# Introduction to dictionaries
# you can also access them similar to a list but it uses keyword values
course = {'teacher':'Ashley', 'title':'Introducing dictionaries', 'level': 'intermediate'}
for key, value in course.items():
print(f"The key is > '{key}': And the value is > '{value}'")
print()
for key, value in course.items():
print(f"{key}: {value}")
##########
print()
print(course)
print()
#############
print(course.keys()) # dict_keys(['teacher', 'title', 'level', 'stages'])
for key in course.keys():
print(key)
print()
################
print(course.values()) # dict_values(['Ashley', 'Introducing Dictionaries', 'Intermediate', 3])
for value in course.values():
print(value)
Here's more on converting to lists etc. for further manipulation.
# Grade 'A' with type casting.
course = {
"teacher": "Ashley",
"title": "Introducing Dictionaries",
"level": "Intermediate",
"stages": 3,
}
# Convert to lists
keys_list = list(course.keys())
values_list = list(course.values())
items_list = list(course.items())
print(keys_list) # ['teacher', 'title', 'level', 'stages']
print(values_list) # ['Ashley', 'Introducing Dictionaries', 'Intermediate', 3]
print(items_list) # [('teacher', 'Ashley'), ('title', 'Introducing Dictionaries'), ('level', 'Intermediate'), ('stages', 3)]
# Slice them like normal lists
print(keys_list[:2]) # ['teacher', 'title']
print(values_list[-2:]) # ['Intermediate', 3]
print(items_list[1:3]) # [('title', 'Introducing Dictionaries'), ('level', 'Intermediate')]
print()
subset = dict(items_list[:2])
print(subset)