# jpl - 2017/03/28 - jlimberger@gmail.com dictc= { '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' : '--..' , '!' : '---.' , '?' : '..--..', '@' : '.--.-.' , '_' : '..--.-' ,} dictd = {} for x in dictc.keys(): dictd[dictc[x]] = x def decodificar(msg): resposta="" palavras=msg.split(' ') for palavra in palavras: letras = palavra.split(' ') for letra in letras: if letra in dictd: resposta = resposta + dictd[letra] else: resposta = resposta + letra resposta = resposta + " " return resposta def codificar(msg): resposta="" palavras=msg.split(' ') for palavra in palavras: for letra in palavra: if letra in dictc: resposta = resposta + dictc[letra] + " " else: resposta = resposta + letra resposta = resposta + " " return resposta print("Decodificando...") print(decodificar("... --- ... ... --- ...")) print("Codificando...") print(codificar("AMEM! QUE TODOS OS SERES SEJAM FELIZES! INCLUSIVE A ROSELEY!!!"))
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question