In the previous exercise we saved information about famous scientists’ names and birthdays to disk. In this exercise, load that JSON file from disk, extract the months of all the birthdays, and count how many scientists have a birthday in each month.
Your program should output something like:
Here is one reader solution using built-in Counters. This reader’s solution did not specify what kind of format the months have to be in, but as you can see from their use of
x.split() to extract the months that they expect the month format to be of the type “May 5, 2010”.
In the previous exercise, I saved birthday information in a slightly different format, so I had to use a slightly different method to extract the months. In my dictionary, the birthdays were saved in the format “MM/DD/YYYY”, or the standard date format we use in the US. My
birthdays.json file looked like this:
To count how many birthdays are in each month, what we need to do is:
Here is my code to do that:
And the output you will see is: