ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print({**{'a': 1, 'b': 2}, 'a': 3})- A. {'a': 1, 'b': 2}
- B. {'b': 2, 'a': 3}
- C. {'a': 3, 'b': 2, 'a': 1}
- D. {'a': 3, 'b': 2}
Correct answer: D. {'a': 3, 'b': 2}
In a dict display the later value for a repeated key wins, and the key keeps the position of its first insertion. So 'a' stays first with value 3.
More Python Programming questions
- What is printed? python a, b, c = [1, 2, 3, 4] print(a, b, c)
- What is printed? python print(12 & -12, 12 & 11, ~12 & 0xF)
- Which loop builds a list of n items in total O(n^2) time in CPython, because each step copies the whole list?
- What is printed? python s = {1, 2, 3} s |= {3, 4} s.discard(9) print(sorted(s), 4 in s, len(s))
- What is printed? python nums = [5, 3, 8] nums2 = nums nums += [1] nums3 = nums[:] nums3.pop() print(nums2, nums3)
- What is printed? python from math import gcd print(gcd(0, 5), gcd(-4, 6), gcd(0, 0))