For this kind of thing, regexps are very useful :
import re
print(re.findall('\blocal\b', "Hello, locally local test local."))
// ['local', 'local']
means word boundary, basically. Can be space, punctuation, etc.
Edit for comment :
print(re.sub('\blocal\b', '*****', "Hello, LOCAL locally local test local.", flags=re.IGNORECASE))
// Hello, ***** locally ***** test *****.
You can remove flags=re.IGNORECASE if you don't want to ignore the case, obviously.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…