
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
split_route(stops)returns a tuple(start, middle, end), wheremiddleis a list of the stops in between. (There are always at least 2 stops.)merge_supplies(base, extra)returns a new dict with both dicts' items; values fromextrawin. Don't change either input.rotate(items)returns a new list with the first item moved to the end. An empty list gives[].
split_route(stops)returns a tuple(start, middle, end), wheremiddleis a list of the stops in between. (There are always at least 2 stops.)merge_supplies(base, extra)returns a new dict with both dicts' items; values fromextrawin. Don't change either input.rotate(items)returns a new list with the first item moved to the end. An empty list gives[].
main.py Python sleeping
Press Run to try your code, then Check to test it.