python can not get my all examples right
<p>For my own understanding, I write 2 functions and use my examples to test. Similarly, both 2 functions have 1 example right and one wrong.
1.
def count_from_word_list(tweet, L):
    """(str, list of str) -> int </p>

<p>The first parameter represents a tweet. The second parameter is a list of words. Count how many times any of the words from the list occur in the tweet, and return the total number.</p>

<pre><code>&gt;&gt;&gt; count_from_word_list('I like him and I like her',  ["like","her"])
3
&gt;&gt;&gt; count_from_word_list('I like him and he likes me',  ["like","her"])
1

"""

count = 0
for i in L:
    if i in tweet:
        count = count + 1
return count
</code></pre>

<p>2.
def contains_hashtag(tweet, h):
    """(str, str) -> bool </p>

<pre><code>The first parameter represents a tweet, and second parameter represents a hashtag. Return True if and only if the tweet contains the hashtag. 

&gt;&gt;&gt; contains_hashtag('I like #csc120', '#csc120')
True
&gt;&gt;&gt; contains_hashtag('I like #csc120', '#csc')
False
"""

if h in tweet:
    return True
else:
    return False
</code></pre>

<h2>First function</h2>

<p>I assume from your example that the body of your first function looks like</p>

<pre><code>def count_from_word_list(tweet, L):
    count = 0
    for i in L:
        if i in tweet:
            count = count + 1
    return count
</code></pre>

<p>Lets think about what is happening in logical steps:</p>

<ol>
<li>You use <code>i</code> to iterate over the list of words to search for.</li>
<li>You then test if <code>i</code> is in <code>tweet</code> using the <code>in</code> keyword.</li>
</ol>

<p>And this is where your error lies. The <code>in</code> keyword in python is used to test if something contains something else. Once python sees that the left hand operand to <code>in</code> is in the right hand operand, it stops, and does not count all the occurrences of the appearance.</p>

<p>If you want to count the number of times a given list of words appear in string do this instead:</p>

<pre><code>def count_occurens_of_words(tweet, word_list):
# create a variable to hold the count in.
# It will be incremented each time we find
# a word in the tweet that contains or matches a
# word from the word_list
count = 0
# for each word in the word_list
for search_word in word_list:
    # for each word in the tweet
    for word in tweet.split(' '):
        # if a word in the tweet contains or matches a word from the word_list
        if search_word == word:
            # increment count
            count += 1
# return count           
return count
</code></pre>

<p><strong>Output:</strong></p>

<pre><code>&gt;&gt;&gt; count_occurens_of_words('I like him and he likes me',  ["like","her"])
2
&gt;&gt;&gt; count_occurens_of_words('I like him and he likes her',  ["like","her"])
3
&gt;&gt;&gt; 
</code></pre>

<h2>Second function</h2>

<p>Assuming that your second function is something such as this:</p>

<pre><code>def contains_hashtag(tweet, h):
    if h in tweet:
        return True
    else:
        return False
</code></pre>

<p>What you need to do is check if any word in the tweet is the hashtag your looking for. When you use <code>in</code> even if the hashtag is a substring of another hashtag it will return true. eg.</p>

<pre><code>def contains_hashtag(tweet, h):
    for word in tweet.split(' '):
        if word == h:
            return True
</code></pre>

python