+ 3

Random result from list in python

How to get random result from a list in Python. I searched for this in the qna section but I can't find any. Please answer or link another post.

14th Jun 2019, 6:27 AM
Yash
Yash - avatar
3 odpowiedzi
+ 7
import random ls = [1,2,3,4,5] // get random item choice = random.choice(ls) print(choice)
14th Jun 2019, 6:39 AM
Trigger
Trigger - avatar
+ 6
To choose a list item randomly you can: import random random.choice(list)
14th Jun 2019, 6:39 AM
ΛM!N
ΛM!N - avatar
+ 3
Thomas Williams ΛM!N Thanks to both of you
14th Jun 2019, 6:42 AM
Yash
Yash - avatar