0 of 6 problems solved • 0%

Exercise prompt

Spot Repeated Codes

Example

Counter produces a frequency table in the order that keys first appear.

from collections import Counter counts = Counter("CABAC") print(list(counts.items())) # [('C', 2), ('A', 2), ('B', 1)] print(counts["Z"]) # 0

The table already has one entry per distinct value. You can inspect each count once.

Your task

Implement repeated_codes(codes) using collections.Counter. Return the codes that occur at least twice, each once, in first-appearance order. The input is a list of case-sensitive strings.

repeated_codes(["X", "A", "A", "X", "B"]) # ["X", "A"]