+ 2

What term can I use to get a random number or letter between a range in python?

I just need to get a random number or letter for example if I had a list = [ "p", "q", "r", "t"] and I wanted to get a reandom letter from list what do I do?

15th Nov 2018, 12:35 AM
Gustavo
Gustavo - avatar
1 Antwort
+ 9
The easiest is probably to use the random.sample() method: from random import sample my_list = ["p", "q", "r", "t"] print(sample(my_list, 1))
15th Nov 2018, 1:46 AM
David Ashton
David Ashton - avatar