A shared packing list should show additions made by either volunteer. The two names do not need two lists: they can refer to one list object. Your first operation will make that sharing visible without relying on a printed memory address.
Function headers include small notes about intended types. In values: list[int], list[int] means a list of integers. The arrow in -> int describes the returned value. A union such as int | None means the result may be an integer or None, which often represents a missing answer. Hints describe a contract; Python does not automatically reject a wrong type because of them.
def first_or_none(values: list[int]) -> int | None:
return values[0] if values else None
print(first_or_none([17, 23])) # 17
print(first_or_none([])) # None
Our alias exercise accepts arbitrary payload objects, so it uses Any, imported from typing, instead of promising integers. list[Any] describes a list whose elements may have different types. The supplied from __future__ import annotations keeps annotations from being evaluated immediately; this will also allow classes to refer to their own type later. You are implementing behavior, not being graded on annotation spelling.
A variable holds a reference to an object. After backup = original, both names refer to the same object. Calling a mutating method through either name changes that object. Reassigning one name is different: it changes what that name refers to, not the other name.
colors = ["ochre"]
label = colors
label.append("teal")
print(colors) # ['ochre', 'teal']
label = ["silver"]
print(colors) # ['ochre', 'teal']
Follow the two statements involving label separately. The method call follows an existing reference and changes the list. The assignment creates a different list and points only label at it. This distinction matters when a function receives a list: the parameter is another name referring to the caller's object.
Rebinding a redirects only its arrow; b still refers to the original list.
append_shared(items, value) must add one value to the end of the caller's list and return that same list. The returned reference lets another caller keep sharing it. Returning items.append(value) would return None, because append changes its receiver but does not return the changed list. Concatenation would create a new outer list and break the identity contract.
An empty list still has identity and can still be shared. Repeated values are allowed; adding an existing value means another entry, not replacing the old entry. Each call adds exactly one reference and leaves existing positions in their original order. List append has amortized O(1) cost; a later lesson will explain why an individual append can cost more. This operation does not copy the list or the object being added.
The first check observes the list after the call and ignores the return value. Once mutation works, the second check asks whether the returned reference is that same list.
items.items itself, not the result of append.Edit main.py, then press Run to inspect the supplied probe. Press Submit to check the operation on additional inputs. You do not need to copy code from another lesson.