# isinword.py -- a code snippet for a friend.
#Simple function that takes a list, finds a keyword in the
#elements of that list and returns the elements that contain
#said keyword or not, depending upon the boolean.
myList = ['appletree','mapletree','pumpkinpie','applepie'] # Here's a list of words
keyword = 'pie' # we want to find the keyword 'pie'
isTrue = True # we want to print every element that contains the keyword 'pie'
def isinword(keyList, keyWord, isTrue): # declare our function
if isTrue: # check for elements containing the keyword
for element in keyList:
if keyWord in element:
print element
if not isTrue: # check for elements without the keyword
for element in keyList:
if keyWord not in element:
print element
isinword(myList, keyword, isTrue) # call the function