Meanwhile, in other categories...
We learned in the last exercise that there has been significantly more sharing of physics prizes since World War II: the ratio of the number of unshared-prize laureates in physics in or after 1945 to the number of shared-prize laureates is approximately 0.13. What is this ratio for prize categories other than physics, chemistry, and medicine?
This exercise is part of the course
Introduction to MongoDB in Python
Exercise instructions
- Save an
$elemMatch
filterunshared
to count laureates with unshared prizes in categories other than ("not in")["physics", "chemistry", "medicine"]
in or after 1945. - Save an
$elemMatch
filtershared
to count laureates with shared (i.e., "share" is not "1") prizes in categories other than["physics", "chemistry", "medicine"]
in or after 1945.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Save a filter for laureates with unshared prizes
unshared = {
"prizes": {____: {
____: {____: ["physics", "chemistry", "medicine"]},
"share": "1",
"year": {____: "1945"},
}}}
# Save a filter for laureates with shared prizes
shared = {
"prizes": {____: {
____: {____: ["physics", "chemistry", "medicine"]},
"share": {____: "1"},
"year": {____: "1945"},
}}}
ratio = db.laureates.count_documents(unshared) / db.laureates.count_documents(shared)
print(ratio)