Write Dictionaries as CSV Records (Exercise)
00:00
In this exercise, you are given a list of Python dictionaries assigned to a variable called favorite_colors
. Each dictionary has the same structure, comprising two key-value pairs, all of which are strings.
00:14
The dictionaries represent people with their favorite colors. Your task is to save this data as rows in a CSV file named favorite_colors.csv
, located in your home directory.
00:28 Notice, however that the expected file content starts with an extra headline with the column names.
00:35 CSV files are more interesting when they include a headline like this because it provides context to the data by clearly labeling each column.
00:45 As always, there are different ways to achieve the desired result. I’m curious if your solution will be similar to mine.
Become a Member to join the conversation.