How can I print my dictionary in a readable format?

This code:

import csv
with open(‘cool_csv.csv’, newline=’’) as cool_csv_file:
cool_csv_dict = csv.DictReader(cool_csv_file)

<csv.DictReader object at 0x7f484e74d8d0>

How do I print out the dictionary in a readable format so that I can get a look at it?

What if it were a list? How would you print its contents?

I’m not sure what you’re getting at.
print(listName) works fine for a list.
for example:

lst = [1, 2, 3]

[1, 2, 3]

print(list(cool_csv_dict)) prints cool_csv_dict converted to a list. The thing that prints out looks more like a list of dictionaries than a dictionary. Is cool_csv_dict a dictionary or a list of dictionaries?

Just before invoking the DictReader, run this code (it will consume the file so the code below won’t have anything; remove when done)…

  for line in cool_csv_file:
    print (line)

We see three values on each line.

Kayla Bridges,28-07-93,Has been to over fifteen different forests.

Jeremy Lopez,12-11-02,Old job was across the street from their new job.

Meredith Barker,05-07-05,Has a dog named Peanut.

William Sanchez,22-11-88,While working a phone bank accidentally called their mother.

Linda Brown,01-02-89,Can whistle the national anthem of twelve different nations.

Elizabeth Smith,23-01-75,Is triple-jointed.

They look to be values of the same type in each position. Each row is then composed as an OrderedDict, but they are all elements of a list object.

[('Cool Name', 'Trevor Torres'), ('Cool Birthday', '03-09-08'), ('Cool Fact', 'Has never been out of the country.')]
[('Cool Name', 'Crystal Ellis'), ('Cool Birthday', '17-11-06'), ('Cool Fact', 'Published a small biography on a local legend.')]
[('Cool Name', 'Devin Patrick'), ('Cool Birthday', '22-09-85'), ('Cool Fact', 'Happened across a major movie star while biking once.')]
[('Cool Name', 'Phyllis Evans'), ('Cool Birthday', '06-02-70'), ('Cool Fact', 'Once ate three packages of cookies in one sitting.')]
[('Cool Name', 'Kayla Bridges'), ('Cool Birthday', '28-07-93'), ('Cool Fact', 'Has been to over fifteen different forests.')]
[('Cool Name', 'Jeremy Lopez'), ('Cool Birthday', '12-11-02'), ('Cool Fact', 'Old job was across the street from their new job.')]
[('Cool Name', 'Meredith Barker'), ('Cool Birthday', '05-07-05'), ('Cool Fact', 'Has a dog named Peanut.')]
[('Cool Name', 'William Sanchez'), ('Cool Birthday', '22-11-88'), ('Cool Fact', 'While working a phone bank accidentally called their mother.')]
[('Cool Name', 'Linda Brown'), ('Cool Birthday', '01-02-89'), ('Cool Fact', 'Can whistle the national anthem of twelve different nations.')]
[('Cool Name', 'Elizabeth Smith'), ('Cool Birthday', '23-01-75'), ('Cool Fact', 'Is triple-jointed.')]

It is a reader object, an example of an iterator object; it can be read through much like a list (in this case, yes, a list of dictionaries), although, as @mtf mentioned, once you go through it, it will be “exhausted.”

The exercise asks you only to iterate through it and return a certain value for each line. Just pretend that cool_csv_dict is a list of dictionaries, each having the same keys (derived from the header row of the .csv file columns), and you will be able to complete it.

What do you mean by “it will consume the file”?
Thanyou in advance!

The file can only be read through once, then needs to be reloaded.

To me, DictReader looks like a list when parsed, why do we call it dictionary?

Because it still contains key-value pairs. Each row would be a single dictionary if we parsed it out of there.