+ 3

How can I randomize some index value in list?

Hello, I'm trying to do a little chatbot, and I wabt to randomize some values in a list (not the entire list), I tried some random lib commands but all gave an error. So, someone have a tip for a random lib code to randomize some values in a list?

5th Nov 2021, 4:37 PM
Katdotbrush
Katdotbrush - avatar
3 Réponses
+ 4
import random list = ['a','b','c','d','f'] rndIndex = random.randint(0,len(list)-1) print(list[rndIndex])
5th Nov 2021, 6:20 PM
JaScript
JaScript - avatar
+ 4
cat do Chrome , there is not everything clear to me. ▪︎what values do you need? numbers, characters, punctuation, ... ? ▪︎have the values to be in a defined range? ▪︎do these values have to be unique ? ▪︎ how many values are required ? ▪︎ are there some values in a list that can be used by rearranging them? if would be great when you could give us samples of the lists. maybe also give a bit more details. thanks!
5th Nov 2021, 6:48 PM
Lothar
Lothar - avatar
+ 2
Guys, I decided to use just two lists for it, because I didn't can to find other way. But, thanks for everyone
5th Nov 2021, 10:47 PM
Katdotbrush
Katdotbrush - avatar