Picking a Random Word from a list in python?
>>> import random
>>> random.choice("hello world".split())
'hello'
>>> random.choice("hello world".split())
'world'
str='book pen paper pencil'
x=str.split()
print(x)
import random
print(random.choice(x))
Use the random.choice()
function:
>>> import random
>>> a = ["Stack", "Overflow", "rocks"]
>>> print(random.choice(a))
rocks