Hi!
I would like to make an ordinary dictionary from english to norwegian, but I have a problem.
I am using this sentence as an example:
"I read the book"
The problem isn't the first two words, but the last ones. :-/
The program should replace "the book" to "boka".
Here is the code so far:
import re
words = {'i':'jeg','read':'leste','the book':'boka'}
while True:
sentence =input('Write something:')
if sentence == 'quit':
break
sentence = sentence.split()
result = []
for word in sentence:
word_mod = re.sub('[^a-z0-9]', '', word.lower())
punctuation = word[-1] if word[-1].lower() != word_mod[-1] else ''
if word_mod in words:
result.append(words[word_mod] + punctuation)
else:
result.append(word)
result = ' '.join(result).split('. ')
print('. '.join(s.capitalize() for s in result))
print('See you!')
I appreciate all the help I can get very much. :icon_smile:
Thank you in advance!