As you will understand from my question, I am new to programming and as most people who are new to this, I am having issues comprehending some of the code. I came across the following code in Python which translates some words from German to English and returns a string of the translation:
deu2eng = {
'ich':'I',
'gehe':'go',
'nach':'to',
'die':'the',
'kirche':'church'}
def trans(eng2deu):
translation = ''
for word in eng2deu.split():
if word in deu2eng:
translation+= deu2eng[word] + ' '
else:
translation += word + ' '
return translation
When I run the following it works:
trans('ich gehe nach die kirche')
However there are some issues. I can't get to understand how I can get it to be case insensitive (e.g. if I type Kirche instead of kirche, it will return Kirche instead of church). I tried using the lower() method to no avail. But most importantly, I do not understand the following line and why it works:
translation+= deu2eng[word] + ' '
From what you can infer, this is quite basic, but I would like to fully comprehend what is happening with this code as I am stuck in the 2 aforementioned things.