🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Design Search Autocomplete: all 10 questions

Quiz: Design Search Autocomplete · Question 2 of 10

What does this print? (code)

What does this print?

top = [(700, "java"), (900, "javascript"), (50, "jam"), (400, "java ide")]
top.sort(key=lambda p: (-p[0], p[1]))
print([q for c, q in top[:2]])
  1. A.['java', 'javascript']
  2. B.['javascript', 'java']
  3. C.['jam', 'java']
  4. D.['javascript', 'java ide']
Answer & explanation

Correct answer: ['javascript', 'java']

Sorting by negative count puts the highest counts first: 900, then 700.

Can you get the rest right without peeking?

Take the timed Quiz: Design Search Autocomplete quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →