+ 1

How to pick a random value from a list

25th Apr 2017, 2:11 PM
Kshitiz Arya
Kshitiz Arya - avatar
2 Answers
+ 11
import random print (range(10)[random.randint(0, 10)]) or, if you have the list named list1 import random print (list1[random.randint(0, 10)])
25th Apr 2017, 2:30 PM
Tato
Tato - avatar
+ 2
import random print(random.choice(['a','b','c']))
25th Apr 2017, 3:14 PM
richard