LearnFrenzy
Sign in Take a free test

Sets · Find the Error · Question 10

Error: pop() from an empty set Answer, explanation & discussion

  • Find the error
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 10 Back to Exercise

The program below stops with an error. Which statement correctly describes the problem?

main.py
pending = {"T1"}
pending.pop()
next_task = pending.pop()
print(next_task)
  • A KeyError: the second pop() runs on an empty set; check if pending: first Correct
  • B IndexError: pop from empty list
  • C It prints None
  • D It prints T1
Correct Answer: Option A

An empty set has nothing to pop; sets report it as KeyError.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links