Why did changing a copied Python request alter the original?

Python & APIsFoundations & codingAbout 8 minutes

Understand the idea, explain it in your own words and use the rubric to find your next learning gap.

Local drafts · no account or AI calls
Sukoaa original

The idea behind the question

Assignment creates another binding to the same object. A shallow copy makes a new outer container but preserves references to nested objects, which matters when requests share mutable metadata.

AN ILLUSTRATIVE EXAMPLE

Two document jobs share a nested tags list after one request dictionary is copied with dict.copy().

TRY A SMALL EXAMPLEPython · standard library
from copy import deepcopy
original = {"tags": ["draft"]}
shallow = original.copy()
isolated = deepcopy(original)
shallow["tags"].append("shared")
isolated["tags"].append("private")
print(original["tags"])
print(shallow["tags"])
print(isolated["tags"])
Show expected output
['draft', 'shared']
['draft', 'shared']
['draft', 'private']
Open Python playground

Copy and paste to run in a separate tab. This example illustrates one concept; it is not a complete application or an automatically graded task.

A practical way to learn it

Run the copy example, predict all three printed lists, then change the code to isolate tags before adding a new tag.

Open Python playground

The related tool opens separately; your interview answer stays here. Written practice is self-guided, without automatic code grading.

Build an explanation you understand

  1. State what the concept does in plain language.
  2. Apply it to the example and make your assumptions explicit.
  3. Explain a trade-off, failure case and how you would test it.
  4. Distinguish your actual experience from a proposed approach.

Further reading

Further-reading links support learning; the reference is Sukoaa-authored, not an official employer answer key.