ProgrammingHardTCS CodeVita · Infosys HackWithInfy · Product Company SDE
What does the following Python 3 code print? a, b = set([12,12,1,7,1]), set([12,12,3,10,6,10]) print(sorted(a ^ b), len(a - b))
- A. [12] 2
- B. [1, 7] 5
- C. [1, 3, 6, 7, 10] 3
- D. [1, 3, 6, 7, 10] 2
Correct answer: D. [1, 3, 6, 7, 10] 2
^ keeps elements in exactly one set (symmetric difference); a − b keeps those only in a. Duplicates collapse when the sets are built. Output: [1, 3, 6, 7, 10] 2.
More Python Programming questions
- What does the following Python 3 code print? def mk(): c = 0 def inc(): nonlocal c c += 2 return c return inc a, b = mk(), mk() for in…
- What does the following Python 3 code print? a, b, c = 25, 3, 17 print((a << b) ^ c, a & ~c, (a | c) >> b)
- What does the following Python 3 code print? def f(): try: return 7 finally: print("f", end=" ") x = f() + 13 print(x)
- What does the following Python 3 code print? a, b = [3,1,8,5,4,7], [7,4,2,5] print(list(map(lambda p: p[0] p[1], zip(a, b)))…
- What does the following Python 3 code print? d = {} for w in ["kheer","ghee","bun","nut","cake","jam"]: d[w[0]] = d.get(w[0], 0) + 1…
- What does the following Python 3 code print? a, b = 18, 5 print(a // b, a % b, -a // b, -a % b)