Sort by a field
The API sends launches in whatever order it likes, and the warehouse lists cargo in the order it was packed. The launch board needs dates in order, and the loading crew wants the heaviest items first, because they go lowest in the racks.
Sort both lists by one of their fields.
Finish stage 1 to unlock this stage.
Print the launches from the earliest date to the latest:
2026-11-05 Lumen-3 2026-11-21 Kestrel-7 2026-12-01 Tern-5 2027-01-18 Polaris Cargo 4
Write launch_date(launch), which returns launch["date"], and pass it to sorted(launches, key=launch_date), without brackets after its name. Leave launches itself in its original order.
Finish stage 1 to unlock this stage.
Print the cargo heaviest first, with the mass and then the item:
42.0 kg Freeze-dried meals 31.3 kg CO2 scrubber cartridges 25.0 kg Rice and lentils 18.5 kg Water filter cartridges 3.4 kg Tablet computers 2.4 kg Spare cabin fan
Write mass(item), which returns item["mass_kg"], and sort with key=mass, reverse=True.
Hints
Functions with Parameters
# Two parameters, separated by a comma
def solar_power(watts_at_earth, distance_au):
return watts_at_earth / (distance_au ** 2)
# The values you hand over at the call are called arguments
print("At Mars:", round(solar_power(1361, 1.52), 1), "W per square metre")
print("At Jupiter:", round(solar_power(1361, 5.2), 1), "W per square metre")
# Order matters. Swap the two and the answer is nonsense
print("Swapped:", solar_power(1.52, 1361))
# Arguments can be variables, not just numbers you typed in
solar_constant = 1361
saturn_au = 9.58
print("At Saturn:", round(solar_power(solar_constant, saturn_au), 1))
# Parameters can be any mix of types
def mission_tag(name, year, crewed):
return f"{name} launched in {year}, crewed: {crewed}"
print(mission_tag("BepiColombo", 2018, False))
# A parameter is a local name. Changing it never touches the original
def rename(label):
label = "changed inside"
return label
original = "untouched outside"
print(rename(original), "|", original)
# Too few arguments, or too many, stops the program
# print(solar_power(1361)) # delete the hash sign to meet a type error
Separate arguments with commas. They're passed on every Run as sys.argv[1:].