dimanche 2 septembre 2018

Python: choosing a value with given probability from a text file [on hold]

I tried looking everywhere on the internet, but my question is quite specific.

I have a .txt file formatted like this

JAMES 3.318 3.318 1

I would like to create a script that chooses a name based on probability (e.g. James with 3.318% of probability). I have more than 2000 entries on the txt file.

My idea was to create a list with all names and another list with associated probabilities. I still have to find a way to do this; moreover, I have no idea on how to make a random choice based on given probabilities on python.

I would be very thankful for your help! Thanks in advance!




Aucun commentaire:

Enregistrer un commentaire