Answers for "randomly choosing all items of an array without repetition python"

0

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]
"""
Posted by: Guest on May-21-2021

Code answers related to "randomly choosing all items of an array without repetition python"

Python Answers by Framework

Browse Popular Code Answers by Language