text = 'Python rocks but Java sucks'

R = {'Python': 'PYTHON', 'Java':'****'}

print('Løsning 1')

def substitute(text, replace):
    new_content = []
    for word in text.split():
        if word in replace:
            new_content.append(replace[word])
        else:
            new_content.append(word)
    return ' '.join(new_content)

print(substitute(text, R))

print('Løsning 2')

def substitute(text, replace):
    new_content = []
    for word in text.split():
        new_content.append(replace.get(word, word))
    return ' '.join(new_content)

print(substitute(text, R))

print('Løsning 3')

def substitute(text, replace):
    return ' '.join([replace.get(word, word) for word in text.split()])

print(substitute(text, R))
