easy +8 pts

Copy deep vs shallow

Distinguish shallow copies from deep copies of nested structures.

In Python, shallow copies share nested objects, while deep copies create fully independent copies. Write a function `check_copy_behavior(original)` that takes a non-empty list `original` containing a nested list at index 0. The function must: 1. Create a **shallow copy** of `original` and assign it to `shallow`. 2. Create a **deep copy** of `original` and assign it to `deep`. 3. Modify the nested list at index 0 inside `shallow[0]` by appending the integer `99`. 4. Return a tuple `(original, deep, shallow)` so the caller can observe that the original and shallow share the nested change, while deep remains unchanged. You must import the required module(s) yourself. The function should not print anything. **Function signature:** `def check_copy_behavior(original: list) -> tuple:`

Constraints

`original` is a non-empty list with at least one element; `original[0]` is a list. The function should not modify `original` in place (only through the shallow copy). The time complexity is O(n) for the deep copy, where n is the total number of elements.

Example

>>> original = [[1, 2], [3, 4]]
>>> orig, deep, shallow = check_copy_behavior(original)
>>> orig
[[1, 2, 99], [3, 4]]
>>> deep
[[1, 2], [3, 4]]
>>> shallow
[[1, 2, 99], [3, 4]]
8 points ~10 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Use the `copy` module: `copy.copy()` for shallow, `copy.deepcopy()` for deep.
Appending to `shallow[0]` also affects `original[0]` because they share the same nested list.
The deep copy should remain unchanged after the modification.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.