Which destination shows up most often in a sample of Irish Rail journeys?
You're looking at a sample of Irish Rail journeys. Which destination appears most often? How could you find out by reading the list just once, even if the same destination keeps turning up?
You've already cleaned the data. Read down the destination column: Cork, Galway, Cork, Limerick, Cork. Each row represents one included journey. The repeated Cork entries are separate journeys, so keep all of them for the tally.
Start with an empty tally. The first Cork row takes Cork from zero to one. When Galway appears, it gets a count of one and Cork stays at one. The next Cork row takes Cork to two. Each destination's count is its frequency.
Your tally currently has Cork at two and Galway at one. The next row says Limerick, which hasn't appeared before. What should change in the tally when you read that row? Pick an answer.
Start with an empty dictionary called counts. The list called destinations holds the clean column in row order. The loop takes one destination at a time. Get returns its current count, or zero if it has no entry yet. Add one and store the result for that destination.
Start with an empty dictionary. The first row gives Cork one, and the second gives Galway one. The third takes Cork to two. The fourth adds Limerick with one. The final row takes Cork to three. Notice how each row changes just one count.
A different tally starts with Galway at three. Now you read a journey to Sligo, followed by another journey to Sligo. What does the dictionary contain after both updates? Pick the tally you would expect.
Count the keys and you get three distinct destinations. Using three as the journey total would be a mistake. Add the counts instead: three plus one plus one is five. That matches the five included journeys. The check can catch a missing update, but it can't tell you whether each count is right.
If you're asked to represent the frequencies graphically, label each destination and use bar height for its journey count. Cork has three journeys, while Galway and Limerick have one each. Cork is the mode in this sample. You could check more journey data to see whether Cork still leads before recommending service changes.