Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Count the letters of balloon with a dictionary. What does max(counts, key=counts.get) give, and is the answer the only possible one?
max() returns the first of equal highest values.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, compare your working with the solution.
The counts are {"b": 1, "a": 1, "l": 2, "o": 2, "n": 1}.
Both l and o appear twice. max returns the first one that it meets with the highest count, which is l.
So the answer is not the only possible one: o is as common as l. A tie is one more reason why a short text can fool the cracker.
Log in to join the discussion.
Loading…