LearnFrenzy
Sign in Take a free test

Dictionaries · Dictionaries MCQ · Question 8

What does setdefault() do? Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 8 Back to Exercise

What does d.setdefault("k", []) do?

  • A Always resets d["k"] to []
  • B Returns [] without changing d
  • C Returns d["k"] if it exists; otherwise sets d["k"] = [] and returns that list Correct
  • D Deletes "k"
Correct Answer: Option C

That is why d.setdefault(k, []).append(x) groups values in one line.

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