ProgrammingEasyInfosys pattern
What is printed?
What is printed?
data = [1, 2, 2, 3, 3, 3]
print({x for x in data if x > 1})- A. {2, 2, 3, 3, 3}
- B. {1, 2, 3}
- C. {2, 3}
- D. {3}
Correct answer: C. {2, 3}
A set comprehension discards duplicates automatically, and the filter keeps only values greater than 1, so the distinct surviving values are 2 and 3.
More Python Programming questions
- What is printed? python print([[y for y in range(x)] for x in range(4)])
- What is printed? python print(list(x for x in range(5) if x % 2 == 0)[1:3])
- What is printed? python print({k: v for k, v in zip(['a', 'b', 'a'], [1, 2, 3])})
- What is printed? python matrix = [[1, 2, 3], [4, 5, 6]] print([[row[i] for row in matrix] for i in range(3)])
- What is printed? python print({x % 3 for x in range(10)})
- What is printed? python def countdown(n): while n > 0: yield n n -= 1 g = countdown(3) print(list(g)) print(list(g))