python random without replacement code example
Example 1: sample 1 item from array python
import random
cakes = ['lemon', 'strawberry', 'chocolate']
random.choice(cakes)
# prints 1 randomly selected item from the collection of n items with
# the probability of selection as 1/n
Example 2: python random select no replace
import random
aList = [20, 40, 80, 100, 120]
print ("choosing 3 random items from a list using random.sample() function")
sampled_list = random.sample(aList, 3)
print(sampled_list)