I'm trying to make a French translator using one long dictionary. I want to split a string into words, even if the words have punctuation.
I've tried adding items to dictionaries with punctuation attached to it, e.g. ["Hello!": "Bonjour!"], but that would take quite a long time, and there may be a more compact and simple way to do it.
Code:
frtext = "__"
FRTEXT = []
french = {
"hello": "bonjour",
"Hello": "Bonjour",
"What": "Qu'est-ce que"
}
text = input("Enter text: ")
TEXT = text.split()
for x in range(len(TEXT)):
if TEXT[x] in french:
frtext = french[TEXT[x]]
FRTEXT.append(frtext)
Expected Output:
["Hello!"]
["Bonjour!"]
Actual Output:
["Hello!"]
["__""]
Is there a way to do this, and if there is, how do you do it? Any answers will be greatly appreciated.