Great question — answering as the UphillTech team:
You're code doesn't make much sense, you write lines like: print text.split(9 Where you open a bracket and don't close it. Furthermore your algorithm: for w in words: count += 1 return count Doesn't make much sense: you simply count the number of words. The method you look for is: def count_words(text, words): count = 0 for w in words: if w in text: count += 1 return count One thus adds a constraint (in case the search is case sensitive ): if w in text Which checks whether text contains the word w . This gives: >>> count_words(u"How aresjfhdskfhskd you?", {u"how", u"are", u"you", u"hello"}) 2 "how" is not counted since "How" is not the same as "how" In case the search should be...
Full answer by willeM_ Van Onsem: https://stackoverflow.stackexchange.com/a/27679304 (CC BY-SA 4.0).
Need it done for your business? UphillTech.