Space Python Loading Python…

Manifest diff

Write the codeEasy 2 stages

The manifest changes every day as items are packed and unpacked. The loading supervisor doesn't want to read both lists side by side: she wants to know what changed.

Work out what was added and what was removed, then how much stayed the same.

Print which IDs were added since yesterday and which were removed, each list sorted:

Added: CG-0047, CG-0048
Removed: CG-0043, CG-0045

set(today) - set(yesterday) is what today has that yesterday didn't. A set has no order, so sort it before joining.

Find the changes
Works for any manifests

Finish stage 1 to unlock this stage.

Add a line with how many IDs are on both lists, and print none when nothing was added or removed:

Added: CG-0047, CG-0048
Removed: CG-0043, CG-0045
Unchanged: 3

set(today) & set(yesterday) is what both lists have.

Count what stayed
Works for any manifests
You're not logged in, so your progress is kept in this browser only. Log in to save it, and to use hints and solutions.

Hints

Mathematical Set Operations

mathematical-set-operations.py
# Asteroids picked up by two different sky surveys last night
catalina = {"Apophis", "Bennu", "Eros", "Didymos"}
panstarrs = {"Bennu", "Didymos", "Ceres", "Vesta"}

# Union: everything either survey saw
print("Seen by anyone:", catalina | panstarrs)
print("Total objects:", len(catalina | panstarrs))

# Intersection: only what both surveys caught
print("Confirmed by both:", catalina & panstarrs)

# Difference: in the first set and not in the second
print("Only Catalina:", catalina - panstarrs)
print("Only Pan-STARRS:", panstarrs - catalina)

# Symmetric difference: seen by exactly one survey, never by both
print("Needs follow-up:", catalina ^ panstarrs)

# Every operator has a spelled-out method that does the same job
print(catalina.union(panstarrs) == catalina | panstarrs)
print(catalina.intersection(panstarrs) == catalina & panstarrs)

# None of that changed the original sets
print("Catalina still holds", len(catalina), "objects")
Open the full example
script.py
PythonLn 1, Col 1Spaces: 4
Loading the Python environment…

Separate arguments with commas. They're passed on every Run as sys.argv[1:].