Skip to content

Instantly share code, notes, and snippets.

@vesche
Last active September 6, 2021 07:29
Show Gist options
  • Save vesche/ada491d63d77d8afa55a599c787df957 to your computer and use it in GitHub Desktop.
Save vesche/ada491d63d77d8afa55a599c787df957 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import requests
MORSE_MAP = {
'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': '--..'
}
url = 'https://raw.githubusercontent.com/dwyl/english-words/master/words_alpha.txt'
words = requests.get(url).text.splitlines()
for word in words:
morse_conv = ' '.join([MORSE_MAP[c] for c in word.upper()])
if morse_conv == morse_conv[::-1] and len(word) > 4:
print(f'{word:12} {morse_conv}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment