Summary

Resources

Notes\ Code

Project Task:

  1. Create a dictionary in this format: {"A": "Alfa", "B": "Bravo"}
  2. Create a list of the phonetic code words from a word that the user inputs.
import pandas
data = pandas.read_csv("nato_phonetic_alphabet.csv")

alphabet_dict = {row.letter: row.code for (index, row) in data.iterrows()}
# print(alphabet_dict)

We start with importing pandas and reading our NATO phonetic alphabet. I then used dictionary comprehension with iterrows() to go through the rows of data one by one and create the alphabet dictionary. I then printed it out to check if it matched the format Dr. Yu mentioned. That’s task 1 done.

word = input("What word? ").upper()
output_check = [alphabet_dict[letter] for letter in word]
print(output_check)

For the final task I got the user input, used upper so each letter would be easier to compare with the upper case letters in the csv I was provided. I used list comprehension to pull the letters from each word and compare them to the dictionary that was just created and add them to the variable holding the output that we print back to the user.

main.py

import pandas
data = pandas.read_csv("nato_phonetic_alphabet.csv")

alphabet_dict = {row.letter: row.code for (index, row) in data.iterrows()}

word = input("What word? ").upper()
output_check = [alphabet_dict[letter] for letter in word]
print(output_check)

nato_phonetic_alphabet.csv

letter,code
A,Alfa
B,Bravo
C,Charlie
D,Delta
E,Echo
F,Foxtrot
G,Golf
H,Hotel
I,India
J,Juliet
K,Kilo
L,Lima
M,Mike
N,November
O,Oscar
P,Papa
Q,Quebec
R,Romeo
S,Sierra
T,Tango
U,Uniform
V,Victor
W,Whiskey
X,X-ray
Y,Yankee
Z,Zulu

Transcript

Let's tackle our project, which is based on a real-life challenge I face. When I'm calling a company, I often need to spell out details over the phone. They'll ask, "What's your name?" and "Can you spell that?" So I'll say "A-N-G-E-L-A," and they respond, "Wait, was that an E? Or a B?"