Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Write a program that counts how many times each letter appears in the word mississippi, and shows the letter that appears most often with its count.
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, go through the solution one step at a time, and check each step against your own.
Plan. Use the counting pattern, and then the "best so far" pattern.
Check. Count by hand: m once, i four times, s four times, p twice. The dictionary is {'m': 1, 'i': 4, 's': 4, 'p': 2}. Two letters tie at 4. The loop uses >, so the first one that reached 4 stays: i.
Answer: i with 4. (s also appears 4 times. The first one found wins, because the test is > and not >=.)
Log in to join the discussion.
Loading…