Advertisement
Guest User

Untitled

a guest
Jul 24th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. .- ...- ..--- .-- .... .. . -.-. -..- ....- .....
  2. -... .... ...--
  3.  
  4. import sys
  5. import re
  6.  
  7. morse_alphabet = {
  8. '' : '',
  9. '.-' : 'A',
  10. '-...' : 'B',
  11. '-.-.' : 'C',
  12. '-..' : 'D',
  13. '.' : 'E',
  14. '..-.' : 'F',
  15. '--.' : 'G',
  16. '....' : 'H',
  17. '..' : 'I',
  18. '.---' : 'J',
  19. '-.-' : 'K',
  20. '.-..' : 'L',
  21. '--' : 'M',
  22. '-.' : 'N',
  23. '---' : 'O',
  24. '.--.' : 'P',
  25. '--.-' : 'Q',
  26. '.-.' : 'R',
  27. '...' : 'S',
  28. '-' : 'T',
  29. '..-' : 'U',
  30. '...-' : 'V',
  31. '.--' : 'W',
  32. '-..-' : 'X',
  33. '-.--' : 'Y',
  34. '--..' : 'Z',
  35. '-----' : '0',
  36. '.----' : '1',
  37. '..---' : '2',
  38. '...--' : '3',
  39. '....-' : '4',
  40. '.....' : '5',
  41. '-....' : '6',
  42. '--...' : '7',
  43. '---..' : '8',
  44. '----.' : '9'
  45. }
  46.  
  47. def converted(line):
  48. converted_line = ''
  49. split_line = re.split('s+', line)
  50. for letter in split_line:
  51. converted_line += morse_alphabet.get(letter)
  52. return converted_line
  53.  
  54. def main(filename):
  55. with open(filename) as input_file:
  56. for line in input_file:
  57. print(converted(line))
  58.  
  59. if __name__ == "__main__":
  60. try:
  61. main(sys.argv[1])
  62. except:
  63. sys.exit("No argument provided / file not found.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement