ProgrammingModerateTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
values = {'x': [1, 2], 'y': [3]}
total = sum(len(v) for v in values.values())
keys = sorted(values, key=lambda k: len(values[k]), reverse=True)
print(total, keys)
  1. A. 2 ['x', 'y']
  2. B. 3 ['x']
  3. C. 3 ['x', 'y']
  4. D. 3 ['y', 'x']

Correct answer: C. 3 ['x', 'y']

The total is 2 + 1 = 3. Sorting by length in descending order puts x first because it has two items.

More Python Programming questions

Exams that ask this topic