I want to convert morse code to english using python 3+ i managed to convert english to morse code using this http://code.activestate.com/recipes/578407-simple-morse-code-translator-in-python/
But I want to convert Morse code to English
I tried to do this one charecter at a time, but the problem is that the Morse code letters are not 1 charecter long, like English letters, so E is "." . and S is "...", the problem is that in the loop of the word there is "." . and match it with E, so instead of getting S, I get "EEE", I tried to fix it by finding spaces and making that word at a time, but instead of looking for letters in the word, it searches for the whole word against the dictionary I'm new to Python and dictionaries, and I donβt know how to distinguish between E "." and S "..." when searching in my dictionary
Here is my code
# defines the dictionary to convert morse to english CODE_reversed = {'..-.': 'F', '-..-': 'X', '.--.': 'P', '-': 'T', '..---': '2', '....-': '4', '-----': '0', '--...': '7', '...-': 'V', '-.-.': 'C', '.': 'E', '.---': 'J', '---': 'O', '-.-': 'K', '----.': '9', '..': 'I', '.-..': 'L', '.....': '5', '...--': '3', '-.--': 'Y', '-....': '6', '.--': 'W', '....': 'H', '-.': 'N', '.-.': 'R', '-...': 'B', '---..': '8', '--..': 'Z', '-..': 'D', '--.-': 'Q', '--.': 'G', '--': 'M', '..-': 'U', '.-': 'A', '...': 'S', '.----': '1'} def main():
This code takes the word and tries to find it against the dictionary, but it doesnβt work. I also tried to find every letter of the Morse codes against the dictionary, but the problem is that you cannot say when the letter starts and ends, so β...β appears like "EEE" instead of "S" and I donβt know how to fix it.
I also tried to find solutions, but found them only in Java, and I don't know Java