def apple_finder(file):
    for line in file:
        if 'apple' in line:
            yield line
source = open('forest', 'rb')
apples = apple_finder(source)
Python: Filter lines from a text file which contain a particular word