Python Collections Quiz

The collections module gives you smarter containers than plain lists and dicts. This Python collections quiz goes deep on Counter, defaultdict, deque, namedtuple and OrderedDict, including the gotchas that come up in interviews.

Hard 10 questions ~8 minutes Pass at 80% Python 3.12

Choose a mode

Playing as a guest: sign in to keep your XP and streak.

Sample question

Question 1 of 10

What does this print?

from collections import Counter
c = Counter("mississippi")
print(c.most_common(2))
Show the answer

A. [('i', 4), ('s', 4)] i and s both appear 4 times. Ties keep the order in which the letters were first seen, and i comes before s in the word.

What this quiz covers

  • Counter counts, ties and arithmetic
  • defaultdict and the keys it creates on read
  • deque with maxlen and fast pops from the left
  • namedtuple fields and immutability
  • What OrderedDict still adds over dict

Questions people ask

Do I need an account?

No. Anyone can play. Sign in to keep your XP, streak, badges and history.

Which Python version?

Python 3.12. Every question about output was checked by running the code.

Can I retake it?

Yes. Your best score is kept, and the questions and answers are shuffled each time.