How can I test different channels in a chain and act differently on some of them? Python

advertisements

What I want to do is look for different strings in a string and act differently upon some of them. Ths is what I have now:

import re

book = raw_input("What book do you want to read from today? ")
keywords = ["Genesis", "genesis", "Gen", "Gen.", "gen", "gen.", "Matthew", "matthew", "Matt", "Matt.", "matt", "matt." ]
if any(keyword in book for keyword in keywords):
    print("You chose the book of: " + book)

I plan to change the "print" at the end to another action later on. So basicly if the user inputs the string "Genisis" then it will take action #1 and if the user inputs "Gen." it will also take action #1 as with all the other forms of the string "Genisis" but if the user inputs the string "Matthew" I want it to take action #2 and it should take action #2 with all the other variations of matthew.

I considered something like this:

book = raw_input("What book do you want to read from today? "
if book == "Genesis":
    print "Genesis"

but that would require lots of lines for all the variations I have listed of "genesis"

I hope someone can help!


book = raw_input("What book do you want to read from today? ").lower().strip('.')
# keywords = ["Genesis", "genesis", "Gen", "Gen.", "gen", "gen.", "Matthew", "matthew", "Matt", "Matt.", "matt", "matt." ]
if book == 'genesis':
    #action1
    pass
elif book == 'gen':
    #action2
    pass
else:
    print('not find the book!')