Exercise: Dictionaries
These exercises combine many of the skills and data types you've learned over the last few units, so you may find yourself consulting previous articles or exercises. For example, the first exercise can be solved nicely with f strings and string methods.
Movie summarizer
Lists of dicts
The next exercises deals with a list of dicts, like:
coords = [
{"x": 1, "y": 2},
{"x": 5, "y": 8}
]
You've dealt with lists before and you've dealt with dicts before, so you can follow the same rules as long as you remember what sort of data type you're retrieving data from. For example, in a list of dicts, you'd use bracket notation with an index to access the first dict, and then use bracket notation with a key to access values inside the dict.
Exercise: Book list
This list stores information about books inside nested dicts:
books = [
{"title": "Uncanny Valley",
"author": "Anna Wiener",
"read": False
},
{"title": "Parable of the Sower",
"author": "Octavia E. Butler",
"read": True
}
]
Now implement count_unread_books
, a function that processes a list of that form and returns the number of unread books in the list.