ProgrammingHardGATE CS & IT · Infosys
What is printed?
What is printed?
from itertools import combinations
a = [1, 2, 3, 4]
cnt = 0
for r in range(1, len(a) + 1):
for c in combinations(a, r):
x = 0
for v in c:
x ^= v
if x == 0:
cnt += 1
print(cnt)- A. 1
- B. 2
- C. 0
- D. 3
Correct answer: A. 1
Only {1, 2, 3} has XOR zero, because 1 ^ 2 ^ 3 = 0. Every other non-empty subset of {1, 2, 3, 4} has a non-zero XOR.
More Python Programming questions
- What is printed? python from collections import Counter def pairseq(a, t): c = Counter(a) total = 0 for x in c: y = t - x if x < y: total…
- What is printed? python import bisect def minlen(a, s): pre = [0] for x in a: pre.append(pre[-1] + x) best = float('inf') for i in…
- What is printed? python people = [('Ann', 30), ('Bob', 25), ('Cid', 30), ('Dan', 25)] s1 = sorted(people, key=lambda p: p[0]) s2 =…
- What is printed? python from itertools import accumulate h = [3, 1, 4, 1, 5, 9, 2, 6] vis = [x for x, m in zip(h, [0] + list(accumulate(h…
- For an array of 10^6 numbers, which approach finds the largest sum of k consecutive elements fastest and correctly?
- Which statement about the bisect module is FALSE?