If I have a a nested list, the change to get a 'c[x]', for example ['c1'] is 2/9; for an 'a' 4/9. The probability to get a c and then an a; or a a and then a c should be. 2/9 x 4/9 + 4/9 x 2/9.
mylist = [['a1'], ['a2'], ['b1'], ['b2'], ['b3'], ['c1'], ['c2'], ['a3'], ['a4']]
r = random.choice(mylist)
print(r)
How would I need to change the code, if i wanna weight to get a 'c', with a 2x rate. The probability should be: 2/9 x2. Supposed my nested list is longer. So in this probability I should get any 'c' more often.
Aucun commentaire:
Enregistrer un commentaire