ProgrammingHardTCS NQT · Wipro pattern

What is printed?

What is printed?
print(len(dict.fromkeys('aab')), list(dict.fromkeys('aab')))
  1. A. 2 ['a', 'b']
  2. B. 3 ['a', 'a', 'b']
  3. C. 2 ['a', 'a']
  4. 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

Exams that ask this topic