ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(len({'a': 1, 'a': 2}), {'a': 1, 'a': 2}, list({1, 2, 1}), sorted({3, 1, 2} & {2, 3, 4}))- A. 2 {'a': 1} [1, 2, 1] [2, 3]
- B. 1 {'a': 1} [1, 2] [2, 3]
- C. 1 {'a': 2} [1, 2] [2, 3]
- D. 1 {'a': 2} [1, 2, 1] [1, 2, 3]
Correct answer: C. 1 {'a': 2} [1, 2] [2, 3]
A repeated dict key keeps one entry, with the last value, so the dict is {'a': 2}. A set drops duplicates, and the intersection of the two sets is 2 and 3.
More Python Programming questions
- What is printed? python print('Ab'.swapcase(), 'ab'.capitalize() == 'Ab', 'AB'.lower() == 'ab', 'a b'.title())
- What is printed? python print(3 > 2 > 1, 3 > 2 and 2 > 1, (3 > 2) + (2 > 1))
- What is printed? python print(sorted([0.5, 1, True, False]), max(0.5, 1, True))
- What is printed? python print('%s|%s' % ('a', 'b'), 'ok', '%5.1f%%' % 99.55)
- What is printed? python print(len(set('aabbcc')), sorted(set('cba')), 'abc'.index('b') + 'abc'.count('b'))
- What is printed? python print(1000000 1000000 == 1012, 0.1 0.1 100 == 1, round(0.1 0.1 100, 10) == 1.0, 2 0.5 == 2 (1 / 2))