How is this wrong?

There's a fundamental problem with your code. Try this test were we compare my solution with yours (choosing all numbers from a space of 100 available choices.

import random

SPACE=100

print("First test")
total_choices=list(range(SPACE))
random_list=[]
for counter in range(SPACE):
    index=random.randint(0,len(total_choices)-1)
    random_list.append(total_choices.pop(index))

assert len(random_list)==len(set(random_list))==SPACE
print("End of first test")


print("Second test")
randomList = []
for counter in range(SPACE):
    randomInteger = random.randint(1,SPACE)
    while(randomList.count(randomInteger) > 0):
        randomInteger = random.randint(1, 10)
    randomList.append(randomInteger)


assert len(random_list)==len(set(random_list))==SPACE
print("End of test")

My code completes the task while your code hangs. If you use that code at production then it can create a serious problem like hanging the entire application.

The important question is: Do you understand why your code hangs with that simple task?

/r/learnpython Thread