I have a specific problem that I just can’t find a solution for.
I get data in the following format from a text file
date1 reason1
date1 reason1
date1 reason2
date1 reason3
date2 reason4
date2 reason1
date2 reason2
date2 reason2
date2 reason1
date2 reason3
date3 reason4
date3 reason4
date3 reason1
I want to build statistics on the data e.g. I want to count all different “reasons” from each date like this
date1 reason1 -> 2
date1 reason2 -> 1
date1 reason3 -> 1
date2 reason1 -> 2
date2 reason4 -> 1
date2 reason2 -> 2
date1 reason3 -> 1
…and so on. How would I parse the data and build the required result? I guess hashes would be used but I failed to imagine a way to solve this.
Here’s a very straight forward approach: