import re file = open('wordlist.txt', 'r') for line in file.readlines(): if re.search('^there$', line, re.I): print line
The re.search function scans the line line and returns true if it finds the regular expression defined in the first parameter, ignoring the case of re.I The ^ symbol means "beginning of line", and the $ symbol means "end of line". Therefore, the search function will return true only if it matches it that precedes the beginning of the line, and it is followed by the end of the line, which itself is isolated.
source share