I'm working on cleaning some text that contains a lot of acronyms. So I have made a dictionary of a few examples and along with their values, however i am running into a few problems with it. Example code below
def acr(text):
acr_dict = {'ft': 'feet'
'mi': michigan }
for word, abr in acr_dict.items():
text = text.replace(word.lower(), abr)
return text
The logic works, but if I have an instance where the letters of the acronym could also be found in certain other words, it will do the following
ex: print(acr('I like milk and live in mi))
output --> I like michiganlk and live in michigan
Any advice on how to not have it look for the acronym letters within other words?