让re.findall()忽略python中的空字符串?

让re.findall()忽略python中的空字符串?,python,regex,Python,Regex,在下面的代码中,当关键字是空字符串时,findall方法会在内容中搜索空格。当给定空字符串时,如何使findall返回0 def match(): row_list = [[1711,"How to find a new fitness fitness fitness fitness gym that will work for you","<p>In general, I like fitness and new things.</p>","https://w

在下面的代码中,当关键字是空字符串时,findall方法会在内容中搜索空格。当给定空字符串时,如何使findall返回0

def match():

    row_list = [[1711,"How to find a new fitness fitness fitness fitness gym that will work for you","<p>In general, I like fitness and new things.</p>","https://www.vida.com/content/how-to-find-a-gym-that-will-work-for-you","","new","gym"],[1711,"How to find a gym that will work for you","<p>Finding a gym is a fun and an exciting part of your health journey. When looking for a gym consider what is important to you. There are many gyms out there from the bare bones gym to the full service athletic club. For example you may want access to a pool and jacuzzi, classes that are included in your membership, specific exercise equipment or child care services.</p>","https://www.vida.com/content/how-to-find-a-gym-that-will-work-for-you","General fitness","new","gym"]]  

    keywords_per_article = []

    for row in row_list:
        content = [row[1],row[2],row[3]]
        keywords = [row[4],row[5],row[6]]
        result_list = []
        for keyword in keywords:
            print keyword
            keyword_list = []
            for content_item in content:
                print content_item
                keywords_found = re.findall(keyword, content_item)
                keyword_number = len(keywords_found)
                keyword_list.append(keyword_number)
                keyword_total = sum(keyword_list)
            result_list.append(keyword_total)
        keywords_per_article.append(result_list)

    print keywords_per_article

用简单的
if
条件将其包围。
[[197, 2, 2], [0, 0, 6]]
                if keyword:
                    keywords_found = re.findall(keyword, content_item)
                    keyword_number = len(keywords_found)
                else:
                    keyword_number = 0