Recap: Crew Roster
Put together keyword arguments, *args and **kwargs, lambda, sorted with key, and map and filter
Mission: Crew Roster
The station keeps a roster of its crew: each person has a name, a role and an age. The captain wants a few quick views of it
- Start your program with two variables: crew, a list of dictionaries, each with a
"name"(a string), a"role"(a string) and an"age"(a whole number), and role, a string. For examplecrew = [{"name": "Ada", "role": "pilot", "age": 36}, {"name": "Ben", "role": "medic", "age": 52}, {"name": "Cy", "role": "pilot", "age": 52}]androle = "pilot" - Write a function pick(people, **match) that returns the people whose values are the same as every value in
match. For examplepick(crew, role="pilot", age=52)returns only Cy. With nomatchat all, it returns everyone - Print
Oldest first:and the names of the whole crew from the oldest to the youngest, joined with,. People of the same age go in the order of their names - Print
Role:, the role,:, and the names of the people with that role in the order of their names, joined with,. If nobody has it, printnoneafter the colon - Print
Ages:and the ages of the whole crew, in the roster's order, joined with a space
Use **match in pick(), sorted() with a key, and map() for the ages. crew has from 1 to 12 people, with different names written in capitals only at the start
Example for the crew and the role above
Oldest first: Ben, Cy, Ada
Role: pilot: Ada, Cy
Ages: 36 52 52