def endcode(msg,secret_d):
for ch in msg:
for key,value in secret_d:
if ch == key:
msg[ch] = value
return msg
encode('CAN YOU READ THIS',{'A':'4','E':'3','T':'7','I':'1','S':'5'})
This is my code. What I am trying to do here is for every characters in a string msg
, the function should search in the dictionary and replace it with the mapping string if the character ch
is a key in the dictionary secret_d
.
If ch
is not a key in secret_d
than keep it unchanged.
For the example, the final result is should be 'C4N YOU R34D 7H15'