randomly choosing all items of an array without repetition python code example

Example: randomly choosing all items of an array without repetition python

from random import sample

items = [-3, -2, -1, 0, 1, 2, 3]
# or just use this:
items = [i for i in range(-3, 4, 1)]

# randomly choosing all items of an array without repetition
for i in range(3):
    sample_space = [i for i in sample(items, items.__len__())]
    print(sample_space)
    
"""
Outputs would be like this: 
[3, 2, 0, -2, -1, 1, -3]
[-2, 3, 1, 0, 2, -1, -3]
[-2, 3, 0, -1, 2, -3, 1]
"""

Tags:

Misc Example