ProgrammingHardCognizant GenC · TCS NQT
What is printed?
What is printed?
a = {1, 2, 3}
b = {3, 4}
print(a ^ b, a.issubset({1, 2, 3, 4}), sorted(a - b, reverse=True), b > {3})- A. {1, 2, 4} False [1, 2] True
- B. {3} True [2, 1] False
- C. {1, 2, 4} True [2, 1] False
- D. {1, 2, 4} True [2, 1] True
Correct answer: D. {1, 2, 4} True [2, 1] True
^ gives the symmetric difference, issubset tests containment, and > means a proper superset. {3, 4} strictly contains {3}, so the last value is True.
More Python Programming questions
- What is printed? python import math print(math.floor(-2.5), math.trunc(-2.5), -7.5 // 2, divmod(7.5, 2))
- What is printed? python def dfs(g, s): seen, out, st = set(), [], [s] while st: u = st.pop() if u in seen: continue seen.add(u)…
- What is printed? python def hanoi(n, a, b, c, out): if n == 0: return hanoi(n - 1, a, c, b, out) out.append((a, c)) hanoi(n - 1, b, a, c…
- What is printed? python from collections import deque def islands(g): R, C = len(g), len(g[0]) seen = set() cnt = 0 for r in range(R): for…
- What is printed? python import heapq def refuel(target, start, stations): h = [] i = 0 fuel = start stops = 0 while fuel < target: while i…
- What is printed? python import heapq def jobs(items): items = sorted(items, key=lambda x: x[0]) h = [] for d, p in items…