i have this code:
word = ["General William Shelton, said the system",
"which will provide more precise positional data",
"and that newer technology will provide more",
"Commander of the Air Force Space Command",
"objects and would become the most accurate metadata"]
i wan to replace:
Replace “the” with “THE”, “
Replace “William Shelton” with “AliBaba”
Replace “data” with “SAMSUNG”
the output should be:
General AliBaba,said THE system which will provide more precise
positional SAMSUNG and that newer technology will provide more
Commander of the Air Force Space Command objects and would become the
most accurate metadata
Thank you!
I have tried this:
rep_word = {"the":"THE", "William Shelton":"AliBaba", "system":"Samsung"}
replace = re.compile(r'\b(' + '|'.join(rep_word.keys()) + r')\b')
result = replace.sub(lambda x: rep_word[x.group()], word)
print result
but i got this error : TypeError: expected string or buffer