Question 15
Back to Exercise
Which expression is a set comprehension?
- A [x * 2 for x in nums]
- B {x * 2 for x in nums} Correct
- C {x: x * 2 for x in nums}
- D (x * 2 for x in nums)
Correct Answer: Option B
Braces with a single expression make a set; with key: value they make a dict; square brackets a list; round brackets a generator.
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!