Replacing values in a list by matching with dictionary

I am trying to replace the values in a list if a match is found with dictionary key. But i am getting the same list as output

Code

data = ['18. September 2021', '7. Juni 1946', 'Mai 2021, 19', '16.9.2021']

dictionary = {"Januar":"January","Februar":"February","März":"March","April":"April","Mai":"May","Juni":"June",
             "Juli":"July","August":"August","September":"September","Oktober":"October","November":"November",
             "Dezember":"December"}

for key in dictionary.keys():
    for index,i in enumerate(data):
        value = i.upper().replace(key, dictionary[key])
        data[index] = value

print(data)

Expected Output

['18. September 2021', '7. June 1946', 'May 2021, 19', '16.9.2021']

Answer

The main problem with your code is the upper(): You convert the date to uppercase, but then try to replace the non-uppercase month names. Remove the upper() entirely, or make the dates uppercase after the replacements.

However, you could also combine the dictionary keys to a regular expression and use re.sub with a callback function to replace them all at once:

>>> import re
>>> p = "|".join(dictionary)
>>> p
'Januar|Februar|März|April|Mai|Juni|Juli|August|September|Oktober|November|Dezember'
>>> [re.sub(p, lambda m: dictionary[m.group()], d) for d in data]
['18. September 2021', '7. June 1946', 'May 2021, 19', '16.9.2021']