0

Is there a way to type ".-" and produce "a"? (python)

New to coding but had an idea. I'm trying to make a morse code translator. I can get it from the letter to morse but not the other way round. Current code example: A = ".-" B = "-..." [etc.] Print (A, B) Output: .- -... Any suggestions?

17th May 2020, 4:00 AM
Morgan Ansell
3 Respuestas
+ 2
Use a dictionary to store the values using the Morse strings as keys. d = {'.-': 'A', '-...': 'B'} morse = '.- -...'.split(' ') message = [] for c in morse: message.append(d[c]) print(''.join(message))
17th May 2020, 4:30 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Use dictionaries. They are collections of key-value pairs. #The string before ':' is the key and the string after is the value. morse = {"A" : ".-", "B" = "-..." , ".-" : "A", "-..." : "B"} #from letter to morse print(morse["A"] + morse["B"]) #from morse to letter print(morse[".-"] + morse["-..."] https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2450/
17th May 2020, 4:34 AM
XXX
XXX - avatar
+ 1
Thanks guys :)
17th May 2020, 4:55 AM
Morgan Ansell