ProgrammingHardTCS NQT · Wipro pattern
What is printed?
What is printed?
print(len(dict.fromkeys('aab')), list(dict.fromkeys('aab')))- A. 2 ['a', 'b']
- B. 3 ['a', 'a', 'b']
- C. 2 ['a', 'a']
- D. 1 ['a']
Correct answer: A. 2 ['a', 'b']
Dict keys are unique, so the repeated a collapses to one key while keeping first-seen order.
More Python Programming questions
- What is printed? python print([x for x in [1, 2, 3] for in range(x)])
- What is printed? python print(sorted(['b10', 'b9', 'a100', 'c2'], key=lambda s: (s[0], int(s[1:]))))
- What is printed? python print(sorted([-2, 1, 2, -1], key=abs))
- What is printed? python print('%5.1f|%-5d|' % (3.14159, 42))
- What is printed? python print(max(range(7), key=lambda i: (i % 3, i)))
- What is printed? python print(5 // 0.5, 5 % 0.5)