Acronym Replacement With It's Value Using Python
i have dictionary like that i need to replace acronyms in text with it's value in dictionary i use this code but it doesn't give me the appropriate result when i test the function
Solution 1:
You can use split
to break your sentence into individual words, then a simple list comprehension to replace desired values:
dct = {'gr8': 'great', 'awsm': 'awesome'}
s = "we are gr8 and awsm"defacronym(s, dct):
return' '.join([dct.get(i, i) for i in s.split()])
print(acronym(s, dct))
Output:
we are great and awesome
Post a Comment for "Acronym Replacement With It's Value Using Python"