So we will again be using a GDP info dictionary to describe the GDP data,
or rather the file within which that GDP data is stored.
You should already be familiar with the GDP info
dictionary structure from the previous project.
This project has three problems within it, so let's take a look at these problems.
For the first problem, we need to create a dictionary that maps
Pygal country codes to World Bank country names.
Now Pygal, like any other plotting library, does not
use country names to indicate which country you're trying to plot data on.
Instead, it uses country codes that are a little less ambiguous, let's say.
So Pygal uses a set of two-letter country codes and so
when you pass data to Pygal asking it to plot on a world map,
you pass it a dictionary where the keys are these two-letter country codes and
the value is the data that you'd like to plot.
In our case, we're going to plot numerical data, which is the GDP data, and
the differences in that numerical data will change the shade of
the color that Pygal uses for that particular country.
So first, we're going to write this function and
we're going to call it reconcile_countries_by_name.
And what we're going to do is take two inputs.
The first is called plot_countries,
which is a dictionary whose keys are the plot library country codes and
the values are the corresponding country name.
Notice I didn't mention Pygal here, right?
We want to write this function such that it'll work with any plot library.
All we really need from the plot library is a dictionary that maps the codes that
that plot library uses to use the names of the countries that those codes
correspond to.
And then our second input is gdp_countries, which is
a dictionary whose keys are the country names that are used in the GDP data.
We don't actually care about the values.
This is very likely the actual GDP information, but
all we need to know is what are the names that are actually used in the GDP data?
This function takes these inputs and
produces a tuple containing a dictionary in a set, so it returns two values.
That dictionary should map country codes from the plot_countries
input to country names from the gdp_countries input.
And so you're going to have to look through the country names that are values
in plot countries and the country names that are keys in GDP countries and
figure out how to make them correspond.
And so everything that appears in both of the inputs
should appear in this dictionary output where I'm mapping the plot country codes
to the country names that are understood in the GDP data.
And then the second return value is just a set, and that set contains all
of the countries codes from plot countries that were not found in GDP countries.
And so I'm going to want to be able to plot those on the map as well and
in different colors so I can show these are all the countries where I couldn't
find any GDP data because I couldn't find the country name in the GDP data that
the plot library was expecting.