def classify(text):
    for category, matches in categories:
        if any(match in text for match in matches):
            return category
return None
How to classify/categorize strings according to regular expression rules in Python