Created
January 15, 2025 22:26
-
-
Save hugomosh/7724f9f3f330a0df4ef82b8e898cb0ba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def natoify(text): | |
""" | |
Translates the given text into the NATO phonetic alphabet. | |
Args: | |
text: The input text to be translated. | |
Returns: | |
A string containing the NATO phonetic alphabet representation of the input text. | |
""" | |
nato_alphabet = { | |
'a': 'Alfa', 'b': 'Bravo', 'c': 'Charlie', 'd': 'Delta', 'e': 'Echo', | |
'f': 'Foxtrot', 'g': 'Golf', 'h': 'Hotel', 'i': 'India', 'j': 'Juliett', | |
'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', ' ': ' ', | |
'0': 'Zero', '1': 'One', '2': 'Two', '3': 'Three', '4': 'Four', | |
'5': 'Five', '6': 'Six', '7': 'Seven', '8': 'Eight', '9': 'Nine', | |
'.': 'Period', ',': 'Comma', '?': 'Question Mark', '!': 'Exclamation Mark', | |
'-': 'Dash', '_': 'Underscore', '/': 'Slash' | |
} | |
nato_words = [] | |
for char in text.lower(): | |
if char in nato_alphabet: | |
nato_words.append(nato_alphabet[char]) | |
else: | |
nato_words.append(char) # Keep non-alphabetic characters as is | |
return ' '.join(nato_words) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment