You will need to:
- make a replacement words dictionary
- get some input
- do sanity checking to make sure it fits your parameters
- split it into a
list
- loop through your new
list
and replace each word with its replacement in yourdict
, if it is in there
I won't write all of this for you. But here's a tip for how to do that last part: use the get
method of dicts - it allows you to provide a "fallback" in case the word is not found in the dict
. So just fall back to the word itself.
replacement_words = {'jan':'janice','foo':'bar'}
my_list = ['jan','is','cool']
[replacement_words.get(word,word) for word in my_list]
Out[41]: ['janice', 'is', 'cool']