Asking for a bit of assistance. This function replaces the abbreviated words with standard spelling. I'm trying to replace lines 3-6 with a list comprehension. I tried this:
words[i] = [key for i, word in enumerate(words) for key, value in abbrevs.items()
if word == abbrevs[key]]
def text_deciphered(text_message, abbrevs):
words = text_message.split()
for i, word in enumerate(words):
for key in abbrevs.keys():
if word == abbrevs[key]:
words[i] = key
words = ' '.join(words)
return words
text_message = "Hey, wat r our plans for tn"
abbrevs = {"what": "wat", "are": "r", "tonight": "tn"}
print(text_deciphered(text_message, abbrevs))
But it merely returns the keys in abbrevs - what are tonight