I want to create a sample of 3 choices from a given dictionary. The dictionary length can be variable.
What I have done in previous code is to create a dictionary of weighted values, in this case 12 values and keys.
Cannot retrieve the sample from my random.choice though.
Using python 3
My dictionary is
dictionary = {'Three': 14.4, 'Five': 11.2, 'Two': 14.4, 'Thirteen': 3.3, 'One': 17.6, 'Seven': 3.3, 'Nine': 3.3, 'Ten': 3.3, 'Twelve': 3.3, 'Eight': 3.3, 'Four': 12.0, 'Six': 10.4}
I try to retrieve a sample of 3 form the random choice of dictionary.
my_sample = random.sample(random.choice(dictionary), 3)
print(my_sample)
But get this error
Traceback (most recent call last):
File "c_weights.py", line 38, in <module>
my_sample = random.sample(random.choice(dictionary), 3)
File "/usr/lib64/python3.3/random.py", line 252, in choice
return seq[i]
KeyError: 11
Trying to get
My_sample = ('One', 'Four','Twelve') for example.
Edit: Just to be clear what I am working towards is.
('One', 'Four','Twelve')
('Two', 'One','Six')
('Four', 'Two','Five')
('One', 'Eight','Two')
('Thirteen', 'Three','Six')
So unique sets built upon weighted probability from within the dictionary(or tuple if that is better)