dimanche 18 juillet 2021

Generate random tuple combination based on their score in Python

I am trying to create a python program, I have 4 list of tuples, I would like to create different 'words', each letter having it's own probability to appear, I would also like the words to be unique.

I first tried creating by assigning probability to each letter, which worked using numpy.random.choice() function.

Now I would like to take the problem from the other side. I put a weight (or score) to each letter (second part of each tuple) so each word I create have a score, here: from 4 to 16. (see below the 4 list of tuple, it's an exemple of what I am working with, the 4 lists are different)

liste1 = [('A',1), ('E',1), ('I',1), ('O',1), ('U',1), ('M',2), ('N',2), ('B',2), ('Y',2), ('R',3), ('E',3), ('T',3), ('G',4), ('J',4)]

liste2 = [('A',1), ('E',1), ('I',1), ('O',1), ('U',1), ('L',2), ('N',2), ('Z',2), ('Y',2), ('R',3), ('E',3), ('P',3), ('F',4), ('X',4)]

liste3 = [('A',1), ('E',1), ('I',1), ('O',1), ('U',1), ('Q',2), ('N',2), ('B',2), ('Y',2), ('R',3), ('E',3), ('T',3), ('H',4), ('J',4)]

liste4 = [('A',1), ('E',1), ('I',1), ('O',1), ('U',1), ('M',2), ('N',2), ('B',2), ('Y',2), ('R',3), ('E',3), ('T',3), ('S',4), ('J',4)]

And what I would like to do is telling my program I want x number of word with a score of 16, and then the program will create randomly x unique words with this score, then also do it for a score of 15, 14 etc...

I have no idea how to do that and I know it is a pretty specific demand, So I would be glad if anyone can bring me an answer.

Thank you for your time!




Aucun commentaire:

Enregistrer un commentaire