Triple plays (mostly) all around
Prizes can be shared, even by more than two laureates. In fact, all prize categories but one – literature – have had prizes shared by three or more laureates.
This exercise is part of the course
Introduction to MongoDB in Python
Exercise instructions
- Save a filter document
criteria
that, when passed todb.prizes.distinct
, returns all prize categories shared by three or more laureates. That is,"laureates.2"
must exist for such documents. - Save these prize categories as a Python
set
calledtriple_play_categories
. - Confirm via an assertion that "literature" is the only prize category with no prizes shared by three or more laureates.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Save a filter for prize documents with three or more laureates
criteria = {____: {____: ____}}
# Save the set of distinct prize categories in documents satisfying the criteria
triple_play_categories = ____(db.prizes.distinct(____, criteria))
# Confirm literature as the only category not satisfying the criteria.
assert set(db.prizes.distinct(____)) - triple_play_categories == {____}