My program doesn't check if there's a duplicate inside a string correctly
<p>I have to do a program that check if there's a duplicate digit inside a 4 number string.
The problem is that like 80% of the times the program classifies as not valid also number which aren't wrong.</p>

<pre><code>import random
def extraction():
    random_number = str(random.randint(1000,9999))
    print(random_number)
    for number in random_number:
        n = 0
        print("number1 ",number)
        for number2 in random_number:
            print("number2 ",number2)
            if(number == number2):
                n = n + 1
                print("n ",n)
                if(n == 2):
                    print("The extracted number is not valid.\n")
                    extraction()
</code></pre>

<p>Why not use the <code>str.count()</code> function?</p>

<pre><code>def extraction():
    random_number = str(random.randint(1000,9999))
    print(random_number)
    if any([random_number.count(i)&gt;1 for i in random_number]):
        print("The extracted number is not valid.\n")
        extraction()
</code></pre>

python