Skip to content

Instantly share code, notes, and snippets.

@JaDogg
Last active October 2, 2017 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JaDogg/afac0ab98e7e6bbeb3c2fb616daca0c6 to your computer and use it in GitHub Desktop.
Save JaDogg/afac0ab98e7e6bbeb3c2fb616daca0c6 to your computer and use it in GitHub Desktop.
Python 3 Dictionary Usage to Calculate Morse Code
#!/usr/bin/env python3
# http://pandabunnytech.com
morse = {"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": "--.."}
phrase = "HELLO WORLD"
print(phrase)
for word in phrase.split():
for ch in word:
print(morse[ch], end=' ')
print(' ' * 7, end='')
print()
@JaDogg
Copy link
Author

JaDogg commented Oct 2, 2017

See Python 3 Dictionary Usage for related python tutorial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment