← Quiz: Python Dictionaries: all 15 questions
Quiz: Python Dictionaries · Question 8 of 15
What does this print? (code)
What does this print?
counts = {}
for ch in "aba":
counts[ch] = counts.get(ch, 0) + 1
print(counts)
- A.{'a': 2, 'b': 1}
- B.{'a': 1, 'b': 1}
- C.{'aba': 1}
- D.An error
Answer & explanation
Correct answer: {'a': 2, 'b': 1}
The classic counting pattern.
Can you get the rest right without peeking?
Take the timed Quiz: Python Dictionaries quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →