Topic: weighted smapling using data from a dictionary

I have the following dictionary.

dict ={'YLE': 6, 'QYL': 36, 'PTD': 32, 'AGG': 145, 'QYG': 34, 'QYD': 34,
'AGD': 188, 'QYS': 35, 'AGS': 177, 'AGA': 154, 'QYA': 23, 'AGL': 16, 'LAU':
1, 'PTA': 7, ' AGY': 7, 'QYY': 19, 'QYE': 6, 'PAT': 57, 'QYT': 28, 'AGT': 10, 'QYQ': 34,
'AGQ': 140, 'QYP': 32, 'AGP': 167, 'TAT': 31, 'SGS': 174, 'TAP': 18, 'YLP':
49, 'TAQ': 23, 'UQE': 5, 'UAQ': 9, 'UAT': 8, 'UAE': 7, 'TAD': 1, 'TAG': 15, 'TAA':
20, 'TAS': 1, 'YUP': 1, 'TAL': 45, 'ALU': 20, 'PEP': 14, 'UAG': 6, 'EAL':
16, 'SYY': 36, 'EAS': 35, 'SYT': 29, 'EAA': 16, 'SYQ': 13, 'EAG': 28}

The keys are the different triplets ,the numbers next to them are the
frequency that they occour in.

I was wondering if there is a way in python to sample them at the
frequecy indicated by the no's next to the key.
So if I did ramdom sampling I would expect to sample QYP  4 times as much as UAT (QYP is 32 and UAT is 8)....ect

I have only given a snippet of the triplet dictionary, the entire dictionary
has about 1400 key entries.
I used random.choice but that is randomly sampling ALL with equal probability.

Thank you,
devaniranjan

Thumbs up