Skip to content

Instantly share code, notes, and snippets.

@drvinceknight
Last active August 29, 2015 14:15
Show Gist options
  • Save drvinceknight/1399653a9305311aa99e to your computer and use it in GitHub Desktop.
Save drvinceknight/1399653a9305311aa99e to your computer and use it in GitHub Desktop.
phrases = ['Cats are nice', 'Dogs are awesome', 'Python is the best', 'I like doughnuts']
words_to_check = ['are', 'awesome', 'brilliant', 'cake']
# This might be your question
print 50 * "="
print 'Checking pairwise'
print 50 * '-'
for pair in zip(phrases, words_to_check): # You don't know the zip command yet I think but look it up and this could easily be done using other tools (iterating over things)
if pair[1] in pair[0]:
print "Yay, '%s' is in '%s'" % (pair[1], pair[0])
else:
print "Oh bother, '%s' is not in '%s'" % (pair[1], pair[0])
print 50 * "="
print 'Checking all words in all phrases'
print 50 * '-'
# This might also be your question
for phrase in phrases:
for word in words_to_check:
if word in phrase:
print "Yay, '%s' is in '%s'" % (word, phrase)
else:
print "Oh bother, '%s' is not in '%s'" % (word, phrase)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment