Let’s say I have a list in python with several strings in it. I do not know the size. How can I run a loop to do an operation on 2 random elements of this string?
What if I wanted to favour a certain subset of the strings in this randomization, to be selected more often, but still make it possible for them to not be chosen?
you need to look into
randommodule. It has for example arandom.choicefunction that lets you select a random element from a sequence or arandom.samplethat selects given number of samples, it’s easy to account for different weights too.