+ 1
Is there a command to randomly pick an item of a list?
2 Answers
+ 2
# Of course!
import random
lst = [1,2,3,4,5]
print(random.sample(lst,3))
# The 3 in the parenthesis means it'll pick 3 random elements from the list
0
Yes, but it needs to be imported from random module.
from random import choice
lst = [1,2,3,4,5]
print(choice(lst)) #2 (for example)