I have a file consists of many strings. Looks like
sdfsdf sdfsdfsdf sdfsdfsdf test gggg uff test test fffffffff sdgsdgsdgsdg sdgsdgsdgsdg uuuttt 5
This should work.
from collections import Counter
with open('myfile.txt', 'r') as f:
words = f.read().split()
counts = Counter(words)
print counts["test"] #counts just of exact string "test"
#find all strings containing test (e.g 'atest', 'mytest')
print sum([val for key,val in counts.iteritems() if "test" in key])