🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Comprehensions and Lambda: all 15 questions

Quiz: Comprehensions and Lambda · Question 9 of 15

What does this print? (code)

What does this print?

print({k: v * 2 for k, v in {"a": 1, "b": 2}.items()})
  1. A.{'a': 2, 'b': 4}
  2. B.{'a': 1, 'b': 2}
  3. C.[2, 4]
  4. D.An error
Answer & explanation

Correct answer: {'a': 2, 'b': 4}

A dict comprehension builds a new dict.

Can you get the rest right without peeking?

Take the timed Quiz: Comprehensions and Lambda quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →