Exercise

Sorting together: MongoDB + Python

In this exercise you'll explore the prizes in the physics category.You will use Python to sort laureates for one prize by last name, and then MongoDB to sort prizes by year:

1901: Röntgen
1902: Lorentz and Zeeman
1903: Becquerel and Curie and Curie, née Sklodowska

You'll start by writing a function that takes a prize document as an argument, extracts all the laureates from that document, arranges them in alphabetical order, and returns a string containing the last names separated by " and ".

The Nobel database is again available to you as db. We also pre-loaded a sample document sample_prize so you can test your laureate-extracting function.

(Remember that you can always type help(function_name) in console to get a refresher on functions you might be less familiar with, e.g. help(sorted)!)

Instructions 1/3

undefined XP
    1
    2
    3

Complete the definition of all_laureates(prize). Within the body of the function:

  • Sort the "laureates" list of the prize document according to the "surname" key.
  • For each of the laureates in the sorted list, extract the "surname" field.
  • The code for joining the last names into a single string is already written for you.

Take a look at the console to make sure the output looks like what you'd expect!