jeudi 13 août 2020

Python Random Choice from Subset of List

  1. I make a random selection from a list
  2. Now based on the value of 1, I want to make another random selection from the same list where the value == 1
  3. I want to now make another random selection where value != 1

e.g

my_list = [a, a, b, c, d, e, a, b]

  1. First random selection index = 1, i.e my_list[idx_1] = a
  2. Second random selection index could be one of (0,6)
  3. Third random selection index could be one of (2,3,4,5,7)

Return value should be index of selection.

Note that filtering the list etc will not work as I need the index in the original list, not the filtered list.




Aucun commentaire:

Enregistrer un commentaire