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>You first need to split the numbers by spaces (as you wish) and turn into a list:</p>

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

<p>Then you can do it either using a set like so:</p>

<pre><code>result = len(set(list1) &amp; set(userlist))
</code></pre>

<p>Where only the non-duplicate common ones will be counted or fix your <code>for</code> loop like so:</p>

<pre><code>def count_correct(list1,list2):

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

    return count
</code></pre>

python