def apply_coder(text, coder):
"""
Applies the coder to the text. Returns the encoded text.
text: string
coder: dict with mappings of characters to shifted characters
returns: text after mapping coder chars to original text
"""
coder_dict = coder
text_list = list(text)
for letter in text_list:
if letter in coder_dict:
letter = coder_dict[letter]
print letter
return ''.join(text_list)
Example: apply_coder("Hello, world!", build_encoder(3)) should return
'Khoor,czruog!'
Instead, it returns
"Hello, world!"
However, if I use a print letter statement in if condition it prints correct letters.
By changing
letter
you are not changing anything in the listtext_list
. You should build a new list instead of the result of the encoding:And that also means you don't first have to make
text
into a list.