Skills101
← All practice quizzes

Quiz: The collections Module

5 questions · new set on every retakeNo time limitPass: 60%+10 XP on first pass

Five ready-made containers that make common programs shorter and faster. Counting with Counter, grouping with defaultdict, fast queues with deque, readable records with namedtuple, and an LRU cache with OrderedDict.

Log in to take the quiz

Free account · see your score, answers and explanations, earn XP

  1. Question 1

    What does this print?

    from collections import Counter
    print(Counter("banana").most_common(1))
    
  2. Question 2

    What does Counter(["x"])["y"] return?

  3. Question 3

    What does this print?

    from collections import defaultdict
    d = defaultdict(int)
    for ch in "aab":
        d[ch] += 1
    print(dict(d))
    
  4. Question 4

    Why is a deque better than a list for a queue?

  5. Question 5

    What does this print?

    from collections import deque
    d = deque([1, 2, 3], maxlen=3)
    d.append(4)
    print(list(d))
    
🎯 Today’s placement challenge — 10 questions, no login. Can you score 10/10?Take today’s challenge →