randomly choosing all items of an array without repetition python

Solutions on MaxInterview for randomly choosing all items of an array without repetition python by the best coders in the world

showing results for - "randomly choosing all items of an array without repetition python"
Philipp
06 Feb 2018
1from random import sample
2
3items = [-3, -2, -1, 0, 1, 2, 3]
4# or just use this:
5items = [i for i in range(-3, 4, 1)]
6
7# randomly choosing all items of an array without repetition
8for i in range(3):
9    sample_space = [i for i in sample(items, items.__len__())]
10    print(sample_space)
11    
12"""
13Outputs would be like this: 
14[3, 2, 0, -2, -1, 1, -3]
15[-2, 3, 1, 0, 2, -1, -3]
16[-2, 3, 0, -1, 2, -3, 1]
17"""