forked from lucasayres/python-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnato.py
More file actions
29 lines (26 loc) · 1013 Bytes
/
nato.py
File metadata and controls
29 lines (26 loc) · 1013 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# -*- coding: utf-8 -*-
def nato(input_file):
"""Convert text to NATO phonetic alphabet.
Args:
input_file (str): Input file.
Returns:
str: Return NATO phonetic alphabet.
"""
dictionary = {
'a': 'Alpha', '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'
}
result = ''
with open(input_file) as f:
for char in f.read():
if char.lower() in dictionary:
result += dictionary[char.lower()] + ' '
elif char == '\n' or char == '\t' or char == ' ':
result += '(space) '
else:
result += char + ' '
return result.rstrip()