easy +10 pts

Garbage Collection Hint

Use reference counting to determine when an object is garbage collected.

In CPython, each object has a reference count. When the count drops to zero, the object is immediately garbage collected and its `__del__` method is called. You are given a class `Tracked` with a `__del__` method that prints `'deleted'`. Write a function `garbage_collection_hint(delete: bool) -> str` that: - If `delete` is `True`, create a `Tracked` object, store it in a variable, delete the variable using `del`, and then return `'deleted'`. - If `delete` is `False`, create a `Tracked` object, store it in a variable, and return `'not deleted'` without deleting the variable. The function should not print anything; only return the string. You must not call `gc.collect()` or import `gc`. The function should rely on the natural behavior of reference counting. Note: The environment may run in an interactive interpreter where the last expression is stored in `_`, which keeps a reference. To avoid that, ensure the object is not the last expression in the function.

Constraints

- The `delete` parameter is a boolean. - Assume CPython behavior (reference counting). - Do not call `gc.collect()`. - The function must return exactly one of the strings `'deleted'` or `'not deleted'`.

Example

>>> garbage_collection_hint(True)
'deleted'
>>> garbage_collection_hint(False)
'not deleted'
10 points ~10 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

The `Tracked` class's `__del__` method is called when the object's reference count drops to zero.
Use `del` to remove the reference to the object when `delete` is `True`.
Make sure the object is not accidentally kept alive by a local variable or any other reference.
Return the appropriate string after the deletion or when the function ends.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.