#!/usr/local/cpython-3.7/bin/python # pylint: disable=superfluous-parens # superfluous-parens: Parentheses are good for clarity and portabilty """ Take a string of numbers and letters, and convert them to the NATO phonetic alphabet. http://en.wikipedia.org/wiki/NATO_phonetic_alphabet """ import re import sys def main() -> None: """Convert to NATO phonetics.""" letters = ( 'alpha bravo Charlie delta echo foxtrot golf hotel India Juliet kilo Lima Mike ' 'November Oscar papa Quebec Romeo Sierra tango uniform victor whiskey x-ray Yankee Zulu' ).split() digits = ( 'ze-ro wun too tree fow-er fife six sev-en ait nin-er' ).split() ord_of_a = ord('a') ord_of_0 = ord('0') for word in sys.argv[1:]: address = '' for suffix in ['@gmail.com', '@yahoo.com']: if word.endswith(suffix): address = suffix word = re.sub('%s$' % suffix, '', word) for char in word.lower(): if 'a' <= char <= 'z': index = ord(char) - ord_of_a print(letters[index]) elif '0' <= char <= '9': index = ord(char) - ord_of_0 print(digits[index]) elif char == '.': print('point') else: print(char) if address: print(address) main()