Issue
I need to generate a unique element each time random choice is run without any repeats each time its run (lists are not allowed to be used )
eg : (x,y,z) (y,x,z) (z,y,x)
from random import choice
operator=random.choice("xyz")
Solution
Is this what you are looking for:
import random
for i in range(5):
print(random.sample("xyz", 3))
['y', 'z', 'x']
['z', 'y', 'x']
['z', 'x', 'y']
['x', 'y', 'z']
['z', 'x', 'y']
I think this is an equivalent solution:
for i in range(5):
x = list("xyz")
random.shuffle(x)
print(x)
Answered By - Bill
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.