Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .- ...- ..--- .-- .... .. . -.-. -..- ....- .....
- -... .... ...--
- import sys
- import re
- morse_alphabet = {
- '' : '',
- '.-' : 'A',
- '-...' : 'B',
- '-.-.' : 'C',
- '-..' : 'D',
- '.' : 'E',
- '..-.' : 'F',
- '--.' : 'G',
- '....' : 'H',
- '..' : 'I',
- '.---' : 'J',
- '-.-' : 'K',
- '.-..' : 'L',
- '--' : 'M',
- '-.' : 'N',
- '---' : 'O',
- '.--.' : 'P',
- '--.-' : 'Q',
- '.-.' : 'R',
- '...' : 'S',
- '-' : 'T',
- '..-' : 'U',
- '...-' : 'V',
- '.--' : 'W',
- '-..-' : 'X',
- '-.--' : 'Y',
- '--..' : 'Z',
- '-----' : '0',
- '.----' : '1',
- '..---' : '2',
- '...--' : '3',
- '....-' : '4',
- '.....' : '5',
- '-....' : '6',
- '--...' : '7',
- '---..' : '8',
- '----.' : '9'
- }
- def converted(line):
- converted_line = ''
- split_line = re.split('s+', line)
- for letter in split_line:
- converted_line += morse_alphabet.get(letter)
- return converted_line
- def main(filename):
- with open(filename) as input_file:
- for line in input_file:
- print(converted(line))
- if __name__ == "__main__":
- try:
- main(sys.argv[1])
- except:
- sys.exit("No argument provided / file not found.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement