Python function checking for common elements using function
<p>The goal is to take two lists see if any elements match and if they do add 1 to count every time. The first list is a list of 5 elements and the second is user input. It doesn't work , what am I doing wrong? It has to be done using a function please help.</p>

<pre><code>userask = input("Enter a few numbers to try win the lotto:      ")


def count_correct(list1,list2):


    count = 0
    for r in list2:
        if list1 in list2:
                count += 1

    return count
</code></pre>

<p>To implement your count function, you can use <a href="https://docs.python.org/2/library/functions.html#sum" rel="nofollow"><code>sum</code></a> with a <a href="https://www.python.org/dev/peps/pep-0289/" rel="nofollow"><em>generator expression</em></a>. </p>

<pre><code>def count_correct(list1, list2):
     # each True in the generator expression is coerced to int value 1
     return sum(i in list1 for i in list2)
</code></pre>

<p><strong>Note</strong> that using <em>sets</em> will eliminate duplicates in your lists, if any, which will give incorrect results.</p>

<hr>

<p>To capture your list of inputs you can do:</p>

<pre><code>userask = input("Enter a few numbers to try win the lotto (separated by spaces):      ")

list1  = map(int, userask.split())
</code></pre>

python