ProgrammingModerateTCS NQT · Accenture
What is printed?
What is printed?
print(list(dict.fromkeys([3, 1, 3, 2, 1])), sorted(set([3, 1, 3, 2, 1]))[::-1])
- A. [1, 2, 3] [3, 2, 1]
- B. [3, 1, 2] [1, 2, 3]
- C. [3, 1, 2] [3, 2, 1]
- D. [3, 1, 2, 3] [3, 2, 1]
Correct answer: C. [3, 1, 2] [3, 2, 1]
dict.fromkeys keeps the first occurrence of each key in order, while sorting the set and reversing it gives descending order.
More Python Programming questions
- What is printed? python def sortcount(a): if len(a) <= 1: return a, 0 m = len(a) // 2 l, x = sortcount(a[:m]) r, y = sortcount(a[m:]) out…
- What is printed? python print([10, 20][True], [10, 20][False])
- What is printed? python print(repr('ab' -1), [1] 0, 'a' 3 == 'aaa')
- What is printed? python print(all([]), any([]), all([0, 1]), any([0, '']))
- What is printed? python print([3, 1].sort() or 'x', sorted([3, 1]) == [1, 3])
- What is printed? python try: try: 1 / 0 except ZeroDivisionError: raise ValueError('bad') except ValueError as e…