ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
print(sorted({'b': 2, 'a': 3}.items(), key=lambda kv: kv[1])[0][0], list({'b': 2, 'a': 3})[-1])
  1. A. a b
  2. B. b b
  3. C. b a
  4. D. a a

Correct answer: C. b a

Sorting by value puts ('b', 2) first, so the first item is 'b'. A dict iterates over its keys in insertion order, so the last key is 'a'.

More Python Programming questions

Exams that ask this topic