Hi I'm new to learning python and I have a project that requires me to translate a document containing a chapter passage into a 'meme' language using a dictionary provided. I'm having an issue getting my code to translate. I don't think I'm quite understanding the syntax needed to make the code work.
Step 1: import text file
file = open("english.txt", "r")
eng = file.readlines()
form_eng = ''.join(eng)
Step 2: import glossary
import json
with open('tranzlashun.json', 'r') as t:
lol = json.load(t)
So my text document is form_eng
and my dictionary is lol
Step 3: Translate the English text into Lolspeak (lol dictionary) Here is the code I'm having a problem with
lol_translation = []
for word, new_word in lol.items():
tran = form_eng.replace(word, new_word.lower())
lol_translation.append(tran)
print(lol_translation)
When I run this, I get the original text document back with all of the letter 'a's missing because 'a' is the first key in my dictionary.
I want to understand the what my code is doing and why and how to fix it.