How would I go about finding out the amount of times a list of keywords has occurred in a list of article titles? I was looking at counter, and came by this solution (How can I count the occurrences of a list item?), and it works great for comparing single words, but not if one of your list has scentences you need to search through. Example:
news_keywords = ['racism','ordeal','hero']
article_list = ['live: suspect in jayme closs case appears in court - cnn', 'woman who helped missing girl describes ordeal - cnn video', 'jayme closs found alive - cnn video', 'suspect in jayme closs case tried to kidnap her twice previously, complaint states', "trump keeps mum on king's comments while separately stoking racism", 'republicans are losing the shutdown blame game', 'government shutdown: live updates - cnnpolitics', "neighbors were 'armed and ready' if suspect in jayme closs kidnapping showed up", "investigators tracking down movements of jayme closs' kidnap suspect", 'sheriff says jayme closs is a hero after she freed herself from captivity and sought help']
a = [[x,article_list.count(x)] for x in set(news_keywords)]
print(a)
Desired output: [['ordeal', 1], ['racism', 1], ['hero', 1]]
Actual output: [['ordeal', 0], ['racism', 0], ['hero', 0]]
I could possibly combine all the list items into a paragraph of sorts and do some kind of search function. But I'm curious how i could do this keeping all the article titles in a list, or at least something iterable.
Edit. So I ended up doing this:
def searchArticles():
article_list = ['live: suspect in jayme closs case appears in court - cnn', 'woman who helped missing girl describes ordeal - cnn video', 'jayme closs found alive - cnn video', 'suspect in jayme closs case tried to kidnap her twice previously, complaint states', "trump keeps mum on king's comments while separately stoking racism", 'republicans are losing the shutdown blame game', 'government shutdown: live updates - cnnpolitics', "neighbors were 'armed and ready' if suspect in jayme closs kidnapping showed up", "investigators tracking down movements of jayme closs' kidnap suspect", 'sheriff says jayme closs is a hero after she freed herself from captivity and sought help']
dump = ' '.join(article_list)
dump_list = dump.split()
a = [[x,dump_list.count(x)] for x in set(news_keywords)]
print(dump_list)
print(a)
But again if there are other ideas, lmk.