I am stuck on a simple way of finding all the instances of a value in a list and randomly selecting one.
I found some stuff on List.index(Value) But it only returns the index of the first instance of that value in my list.
Is there some simple way of returning a list of all the occurrences of the value. Example:
Instances = List.allindexes(Value) # for example
SelectedIndex = random.choice(Instances)
Aucun commentaire:
Enregistrer un commentaire