ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
print(len({'a': 1, 'b': 2}), len({'a', 'a', 'b'}), len(dict.fromkeys('hello')))
  1. A. 2 3 5
  2. B. 2 2 4
  3. C. 2 2 5
  4. D. 1 2 4

Correct answer: B. 2 2 4

A dict literal with two distinct keys has two entries, and a set literal removes the duplicate a. dict.fromkeys over 'hello' keeps the four distinct letters h, e, l and o.

More Python Programming questions

Exams that ask this topic