—
Aliasing and shallow copy
Tutor me on https://mlprep.pages.dev/item/original-py-alias-copy/. This is a practice item. If window.mlPrepAgent is available, read attempts for item original-py-alias-copy before tutoring. Inspect my attempt, keep the item ID, and do not reveal the full answer first. After a real attempt, append its record with recorded_by agent, include agent_session_id when available, and read it back. Keep the tutoring session self-contained in this chat. Fetch the problem and any available reference solution from ML Prep or the cited source. Include everything I need to solve the problem without opening a link. Present the problem without hints and wait for my attempt or a request for help. You may include an optional hint only if this chat supports a reveal control that actually hides it by default. Show the solution only when I ask or when we review my attempt. Say if you can't access the problem or reference solution, and distinguish your own solution from the reference.Problem
Implement alias_copy_state(). Construct a = [[1], [2]], let b = a, and let c = a.copy(). Append 3 to a[0], then append [4] to a. Return (a, b, c). Predict the result before running it.
Starter code
def alias_copy_state():
passReveal answer or reference solution
def alias_copy_state():
a = [[1], [2]]
b = a
c = a.copy()
a[0].append(3)
a.append([4])
return a, b, cPublic tests
alias_copy_state()→([[1, 3], [2], [4]], [[1, 3], [2], [4]], [[1, 3], [2]])
Previous attempts
Loading attempts saved in this browser…