+ 3

How can I select a random item of a list in python?

3rd Jan 2019, 12:02 PM
fernanch el crack
fernanch el crack - avatar
5 Answers
+ 6
import random print(random.choice(List_name))
3rd Jan 2019, 12:11 PM
Mayank Dhillon
Mayank Dhillon - avatar
+ 4
Import random Numbers=list(range(1,100) Num=random.choice(numbers) A random number will be chosen.
4th Jan 2019, 9:54 PM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar
+ 3
l=[1,2,3,4] X=l[random.randint(0,len(l)-1)]
3rd Jan 2019, 12:14 PM
Pulkit Kamboj
Pulkit Kamboj - avatar
+ 2
1: import random 2: list= ['r', 's', 't', 'l', 'k'] print(random.choice(list)) could slice also
4th Jan 2019, 6:43 AM
Markpeach96
Markpeach96 - avatar
+ 1
import random list = [1,2,3,4,5,6,7,8,9] x = random.sample(list,1) print(x)
3rd Jan 2019, 2:09 PM
Tygo
Tygo  - avatar