LearnFrenzy
Sign in Take a free test

Sets · Predict the Output · Question 9

Set comprehensions Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 9 Back to Exercise

What is the output of the following Python program?

main.py
print({x % 3 for x in range(10)}, sorted({len(w) for w in ["hi", "to", "sea", "a"]}))
  • A {0, 1, 2, 0, 1, 2, 0, 1, 2, 0} [2, 2, 3, 1]
  • B {1, 2, 3} [1, 2, 3]
  • C {0, 1, 2} [2, 3, 1]
  • D {0, 1, 2} [1, 2, 3] Correct
Correct Answer: Option D

Only the distinct remainders 0, 1, 2 and the distinct lengths 1, 2, 3 survive.

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