Now we're finally ready to tackle our project,
and this project is based on a real-life struggle that I have. Often when I'm
calling a company and over the phone I have to give some sort of details
right? They'll ask me, what is your name, and can you spell it?
So I'll have to be like A-N-G-E-L-A. And they're like, wait, was that an E?
Was that a B, what did you say? In these cases
often I have to sort of default to some sort of Naval alphabet. where
I say A is the alfa, N for November, G for golf.
And then at some point I forget what E stands for and I'm like E for.. elephant?
And there have been times where I've just completely taken the MIG and said
things like M for mnemonic, P for pneumonia, W for wrench,
which doesn't make any sense at all
because these are silent letters. And I've had some very angry people,
um, but it was quite fun.
So now what we want to create is we want to create a tool that takes the NATO
phonetic alphabet which was generated because it's often really,
really important for the other side to know exactly what it is that you said and
which letters you're spelling out so that they don't mistaken your E for a B or
your T for a C
cause it all sounds really similar. Head over to the course resources page
where you can find the starting files for the NATO alphabet project.
I want you to practice with list comprehension and with dictionary
comprehension. But in this case,
we're not going through a dictionary per se,
but we're actually going through a data frame because our data lives inside a
CSV. So we're going to be reading it using pandas.
and then we're going to end up with a data frame. Instead of having a bog
standard dictionary comprehension where our keywords were new_key:
new_value for key, value in dict.items.
Now we're going to change this for-loop
so instead of using the simple for loop where
we're just looping through a dictionary,
we're going to use this particular loop. So then in this case,
we're saying for index row in our data frame,
and then it's .iterrows as the method.
So basically I want you to use this different loop in order to loop through our
data frame and then create a new dictionary using a new key and new value.
So what exactly is it that I want you to do with this? Well,
I want you to be able to take the CSV of NATO phonetic alphabet,
and I want you to do two things to it.
The first thing is for you to create a dictionary in this format.
The format is basically the key is going to be the actual letter,
so maybe A. And then the value is going to be the corresponding code for the NATO
phonetic alphabet. So A actually is for alpha.
And then the next one is B, which stands for Bravo.
Essentially,
we're going to take the CSV and we're going to convert it into a dictionary in
this particular format where the keys
are the letters inside the CSV, so that first column,
and then the values are the corresponding code words for each of those letters.
And the reason why we're talking about iterrows and had to loop through rows of a
data frame instead of just getting you to get hold of the data frame
and then just say to_dict
like what we did before, is because it's not going to give it to you in this
particular format.
So you're going to have to use what you've learned about dictionary
comprehension in order to create a dictionary in this particular format.
And then once you've created a dictionary in this format,
then the next step is a lot easier.
You are going to create a list of the phonetic code words from a word that the
user inputs.
That way the user can use the input to type a word.
So for example, Thomas, and then when they hit enter,
they get a list printed out
that is the phonetic alphabet code word for each of the letters in their input.
So Tango, Hotel, Oscar Mike, Alpha Sierra,
which they can then read back using our little tool.
I would say that to do step 1 is a lot harder than to do step 2.
But essentially, to do step 1 is a dictionary comprehension,
creating a dictionary in this format from the CSV, and to do
number 2 is basically completing the project and being able to create and
print out a list of the code words based on the word that the user inputs.
So I want you to pause the video, have a think about how you might solve this,
and then go ahead to the course resources and download this starting zip file so
that you can open it up inside PyCharm and create your project.
Pause the video and give that a go now.