I'm creating a small Virtual Assistant project that uses speech recognition to help me get more advanced with Python. I've currently made it able to get the weather for a given city, or the current location, also simple arithmetic (adding, subtracting, etc) and getting the news using newsapi.org.
I would like to know how to speed up the process of identifying keywords using if statements. For example, right now I have something like this:
if "weather" in voiceRgn and "here" in voiceRgn or "weather" in voiceRgn:
#current location weather function
elif "weather" in voiceRgn and "in" in voiceRgn and "current" not in voiceRgn and "my" not in voiceRgn:
# given city/place weather function
elif "articles" in voiceRgn or "news" in voiceRgn or "headlines" in voiceRgn:
# list news headlines function
As you can see it's very long and probably inefficient. Is there a way to shorten this, so that maybe it's given a list of words and if the clip contains something along the list of words, it runs the function?