How do you return a random result from a list in python? | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
0

How do you return a random result from a list in python?

If you had: Words = ["yes","no","maybe"] How would you?

8th Aug 2019, 12:30 PM
coffeecup
coffeecup - avatar
12 Respuestas
+ 4
In Python do: import random Words = ["yes", "no", "maybe"] print(random.choice(Words))
8th Aug 2019, 1:02 PM
Paul Grasser
Paul Grasser - avatar
8th Aug 2019, 12:58 PM
᠌᠌Brains[Abidemi]
᠌᠌Brains[Abidemi] - avatar
+ 2
Paul Grasser yeah i deleted my comment, i thought he wanted to sort the array randomly, thx
8th Aug 2019, 1:07 PM
᠌᠌Brains[Abidemi]
᠌᠌Brains[Abidemi] - avatar
+ 2
Thank you Paul Grasser
8th Aug 2019, 1:22 PM
coffeecup
coffeecup - avatar
+ 1
᠌᠌brains I think he wanted to select a random element from the list. For this random.choice is better.
8th Aug 2019, 1:04 PM
Paul Grasser
Paul Grasser - avatar
+ 1
Oh do @ their name (but no space)
8th Aug 2019, 1:17 PM
Paul Grasser
Paul Grasser - avatar
0
sorry
8th Aug 2019, 12:58 PM
coffeecup
coffeecup - avatar
0
it's in Python
8th Aug 2019, 12:59 PM
coffeecup
coffeecup - avatar
0
Yes that is right
8th Aug 2019, 1:05 PM
coffeecup
coffeecup - avatar
0
The shuffle thing is also very helpful thx
8th Aug 2019, 1:08 PM
coffeecup
coffeecup - avatar
0
By the way, how do you make a hyperlink to another profile like both Paul grasser and brains did?
8th Aug 2019, 1:10 PM
coffeecup
coffeecup - avatar
0
Thx
8th Aug 2019, 1:22 PM
coffeecup
coffeecup - avatar