🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Python Interview Programs: all 13 questions

Quiz: Python Interview Programs · Question 11 of 13

What does this print? (code)

What does this print?

text = "swiss"
counts = {}
for ch in text:
    counts[ch] = counts.get(ch, 0) + 1
print(next(ch for ch in text if counts[ch] == 1))
  1. A.s
  2. B.w
  3. C.i
  4. D.ws
Answer & explanation

Correct answer: w

s appears 3 times; w is the first character that appears exactly once.

Can you get the rest right without peeking?

Take the timed Quiz: Python Interview Programs quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →