message=input(">")
words=message.split(' ')
print (words)
emoh={
":)":"😂",
":(":"😒"
}
output=""
for word in words:
print(word,word,word,word,word)
print (emoh.get(word))
output+= (emoh.get(word,word))
print (output)
message=input(">")
words=message.split(' ')
print (words)
emoh={
words[0]:"😂",
words[1]:"😒"
}
output=""
for word in words:
print(word,word,word,word,word)
print (emoh.get(word))
output+= (emoh.get(word,word))
print (output)
Open in new window
also in the first print. The first word is used as a key to the dictionary. If it is not in the dictionary, the second value is used as a default. So, or the word is translated, or you get the same word -- as you do it correctly in the next command.A side note: Python strings are immutable. This means that they cannot be modified. This means that the output += emoh.get(word, word) always constructs a new string and throws away the older content. That can be very inefficient if you use large texts.