A dictionary puts a value next to each key: {"a": 3, "b": 1}. A set answers "is it there?"; a dictionary answers "how many?" or "where?".
count = {}for v in values:count[v] = count.get(v, 0) + 1
count.get(v, 0) gives v's count if it was seen before, and 0 if not. So the first meeting writes 1 without an error.Once the counting is done you can walk the dictionary: for value, n in count.items(). Finding the most frequent is the "best so far" pattern you know, run over a dictionary.