Q:

Trying to produce a Random list of single digit integers which are not repeated. Getting only 5 instead of 9

Here is my code
from random import randint
SudList = []
numbers = [1,2,3,4,5,6,7,8,9]
for i in numbers:
    SudList.append(numbers[randint(0,len(numbers)-1)])
    print("Sudlist-" + str(SudList))
    numbers.remove(SudList[-1])
    print("numbers-" + str(numbers))
print(SudList)

I expected this code to return something like this- (the final SudList)
[9,7,2,8,6,4,5,3,1]

But Instead it Returns something like this -
[9,4,6,7,2]

Here is the whole output-
Sudlist-[5]
numbers-[1, 2, 3, 4, 6, 7, 8, 9]
Sudlist-[5, 1]
numbers-[2, 3, 4, 6, 7, 8, 9]
Sudlist-[5, 1, 9]
numbers-[2, 3, 4, 6, 7, 8]
Sudlist-[5, 1, 9, 3]
numbers-[2, 4, 6, 7, 8]
Sudlist-[5, 1, 9, 3, 4]
numbers-[2, 6, 7, 8]
[5, 1, 9, 3, 4]
Press any key to quit

How do i correct my code? 

A:

You can use shuffle. It's will meet your needs.
import random
random.shuffle(numbers)

output
[7, 4, 3, 2, 1, 8, 6, 5, 9]

A:

If you wish to stick with this piece of code, simply use i in range len(numbers) instead of i in numbers. Your remove statement is reducing the length of numbers and thus, the number of numbers printed is always (len(numbers)+1)/2
from random import randint
SudList = []
numbers = [1,2,3,4,5,6,7,8,9]
for i in range(len(numbers)):
    SudList.append(numbers[randint(0,len(numbers)-1)])
    print("Sudlist-" + str(SudList))
    numbers.remove(SudList[-1])
    print("numbers-" + str(numbers))
print(SudList)

