return a random item from a list code example
Example 1: sample 1 item from array python
import random
cakes = ['lemon', 'strawberry', 'chocolate']
random.choice(cakes)
Example 2: python randomly sample entry from a set
import random
random.sample(your_set, number_of_elements)
your_set = {'a', 'bunch', 'of', 'unique', 'words'}
random.sample(your_set, 1)
--> ['words']
random.sample(your_set, 3)
--> ['words', 'of', 'a']
Example 3: select a random element from a list python
import random
listofnum = [1, 2, 3, 4, 5]
print(random.choice(listofnum))
random.shuffle(listofnum)
print(listofnum)