Code

Unpacking with *

You know a, b = b, a swaps two values. Add a star and one name can scoop up "everything else" as a list:

route = ["Mossreach", "Ashfall", "Brine", "Glimmer"]

first, *rest = route        # rest = ['Ashfall', 'Brine', 'Glimmer']
*before, last = route       # last = 'Glimmer'
start, *middle, end = route # middle = ['Ashfall', 'Brine']
head, *_ = route            # _ means "I don't care about these"

Stars also spread collections out when building new ones:

a, b = [1, 2], [3]
both = [*a, *b, 4]                   # [1, 2, 3, 4]

base = {"rope": 1, "lamp": 1}
extra = {"lamp": 3, "map": 1}
merged = {**base, **extra}           # later keys win
# {'rope': 1, 'lamp': 3, 'map': 1}

Both build new objects; the originals are untouched.

Assignment

  1. split_route(stops) returns a tuple (start, middle, end), where middle is a list of the stops in between. (There are always at least 2 stops.)
  2. merge_supplies(base, extra) returns a new dict with both dicts' items; values from extra win. Don't change either input.
  3. rotate(items) returns a new list with the first item moved to the end. An empty list gives [].