Unit: Unit 5: Dictionaries and Sets • Interactive Practice
Interactive Python programming tutorial and practice in your browser.
# Practice set pop() and clear()
worker_tasks = {"task_audit", "task_backup"}
# 1. Pop an arbitrary element from the set
popped_task = worker_tasks.pop()
is_valid_task = popped_task in ["task_audit", "task_backup"]
# 2. Clear all remaining items from the set
worker_tasks.clear()
print("Task successfully popped:", is_valid_task)
print("Set after clear:", worker_tasks)
print("Length after clear:", len(worker_tasks))