random | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

random

please helo me. how to use random with a list give an example

19th Oct 2016, 7:17 PM
Rodrigo Tallar
Rodrigo Tallar - avatar
2 Answers
+ 1
let your list be:- lst=[1,2,3,4] using random function, rand_item=random.choice(lst) #assigning the random value to the variable 'rand_item'
19th Oct 2016, 7:44 PM
Vishodu Shaozae
Vishodu Shaozae - avatar
0
what he said is correct^ use random.choice('name_of_your_list)
9th Jan 2017, 2:50 AM
ramzi
ramzi - avatar