ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
print(list(dict.fromkeys('mississippi')))
  1. A. ['m', 's', 'i', 'p']
  2. B. ['m', 'i', 's', 'p']
  3. C. ['i', 'm', 's', 'p']
  4. D. ['m', 'i', 's', 'p', 'i']

Correct answer: B. ['m', 'i', 's', 'p']

dict.fromkeys keeps the first occurrence of each key, in insertion order. This is a common way to remove duplicates while keeping order.

More Python Programming questions

Exams that ask this topic