My code...
sentence = "hello world helloworld"
dictionary = {"hello": "1", "world": "2", "helloworld": "3"}
for key in dictionary:
sentence = sentence.replace(key, dictionary[key])
print(sentence)
What I want it to do...
1 2 3
What it actually does...
1 2 12
sentenceonly contains words from the dictionary, or if other words are possible. Also in the current form you will get an error:AttributeError: 'list' object has no attribute 'replace'