Back to Lesson

State Cleanup

Safely remove elements from dictionaries using popping methods.

Instructions

  • Given
    session = {"id": 101, "user": "admin", "token": "xyz", "expires": "today"}
    .
  • Remove
    "token"
    using the
    .pop()
    method and store the value in a variable. Print that value.
  • Attempt to remove
    "cache"
    using
    .pop("cache", "No cache")
    and print the result.
  • Print the final
    session
    dictionary.
main.py
main.py